Skip to content

Instantly share code, notes, and snippets.

@npjc
Created July 7, 2016 05:14
Show Gist options
  • Save npjc/f100a212ab3713e4e34be01f4d4d16c2 to your computer and use it in GitHub Desktop.
Save npjc/f100a212ab3713e4e34be01f4d4d16c2 to your computer and use it in GitHub Desktop.
make-a-random-tibble
# install.packages(c("purrr", "tibble"))
rtibble <- function(n_obs = 10) {
tibble::tibble(
lgl = purrr::rbernoulli(n_obs),
int = purrr::rdunif(n_obs,sample.int(1e3, 1, replace = T)),
dbl = rnorm(n_obs),
chr = sample(letters, n_obs, replace = T),
fctr = as.factor(sample(letters, n_obs, replace = T))
)
}
rtibble()
#> # A tibble: 10 x 5
#> lgl int dbl chr fctr
#> <lgl> <dbl> <dbl> <chr> <fctr>
#> 1 TRUE 28 0.72836209 j m
#> 2 FALSE 51 0.42573447 w q
#> 3 FALSE 65 -0.05597711 d n
#> 4 FALSE 48 1.53171519 q c
#> 5 FALSE 92 0.14830575 o v
#> 6 TRUE 97 -1.72330673 c x
#> 7 FALSE 22 -0.67494448 l s
#> 8 FALSE 63 -0.53452315 q q
#> 9 TRUE 6 0.66633605 a y
#> 10 FALSE 6 1.03173174 h r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment