r_sample: Generate Random Vector

Description Usage Arguments Value See Also Examples

Description

Generate a random vector.

Usage

1
r_sample(n, x = 1:100, prob = NULL, name = "Sample")

Arguments

n

The number elements to generate. This can be globally set within the environment of r_data_frame or r_list.

x

A vector of elements to chose from.

prob

A vector of probabilities to chose from.

name

The name to assign to the output vector's varname attribute. This is used to auto assign names to the column/vector name when used inside of r_data_frame or r_list.

Value

Returns a random vector of elements.

See Also

sample

Examples

1
2
3
4
r_sample(100, name = "Var")
table(r_sample(x = c("Dog", "Cat", "Fish", "Bird"), n=1000))
r_sample(x = c("B", "W"), prob = c(.7, .3), n = 25, name = "Race")
r_sample(25, x = c(TRUE, FALSE))

Example output

  [1] 64 79 68 95 15 14 90 78 61 32 64 19 31 45 34 98 61 79 62  3 27 96 96 69 30
 [26] 23 78 59 91 79 60 85 22 59 87 85 27 15 18 37 29 75 36 25 77 64 98 77 12 75
 [51] 97  6 28 74 69  8 23 98 43 87 55 68 82 49 82 95  6 65 35 56 43 48 27  9 54
 [76] 61 95 15 51 17 93 54 42 44 41 49 72 52 64 95 36 70 92 88 80 24 40 62  5  6

Bird  Cat  Dog Fish 
 251  235  268  246 
 [1] "B" "W" "B" "B" "B" "W" "B" "B" "B" "B" "B" "B" "B" "W" "B" "B" "B" "B" "W"
[20] "B" "W" "W" "B" "B" "B"
 [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE
[13]  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
[25]  TRUE

wakefield documentation built on Sept. 14, 2020, 1:07 a.m.