r_list: List Production (From Variable Functions)

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/r_list.R

Description

Produce a named list that allows the user to lazily pass unnamed wakefield variable functions (optionally, without call parenthesis).

Usage

1
r_list(n, ..., rep.sep = "_")

Arguments

n

The length to pass to the randomly generated vectors.

rep.sep

A separator to use for repeated variable names. For example if the age is used three times (r_list(age, age, age)), the name "Age" will be assigned to all three vectors in the list. The results in column names c("Age_1", "Age_2", "Age_3"). To turn of this behavior use rep.sep = NULL. This results in c("Age", "Age", "Age") for vector names, leading to c("Age", "Age.1", "Age.2") if coerced to a data.frame.

...

A set of optionally named arguments. Using wakefield variable functions require no name or call parenthesis.

Value

Returns a named list of equal length vectors.

Author(s)

Josh O'Brien and Tyler Rinker <tyler.rinker@gmail.com>.

References

https://stackoverflow.com/a/29617983/1000343

See Also

r_data_frame, r_series r_dummy

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
r_list(
    n = 30,
    id,
    race,
    age,
    sex,
    hour,
    iq,
    height,
    died,
    Scoring = rnorm
)

r_list(
    n = 30,
    id,
    race,
    age(x = 8:14),
    Gender = sex,
    Time = hour,
    iq,
    height(mean=50, sd = 10),
    died,
    Scoring = rnorm
)

Example output

$ID
 [1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"

$Race
 [1] White    Hispanic Hispanic White    White    White    White    Hispanic
 [9] White    Asian    Black    White    White    White    Hispanic Black   
[17] White    White    White    White    Asian    White    White    White   
[25] White    White    White    White    White    Native  
Levels: White Hispanic Black Asian Bi-Racial Native Other Hawaiian

$Age
 [1] 84 88 49 26 78 76 26 79 81 41 69 27 27 64 54 52 23 49 39 48 47 88 60 78 65
[26] 42 84 25 55 77

$Sex
 [1] Female Female Male   Male   Female Female Male   Male   Male   Female
[11] Female Male   Male   Female Female Male   Male   Male   Male   Male  
[21] Female Male   Male   Female Male   Female Male   Male   Male   Male  
Levels: Male Female

$Hour
 [1] 00:30:00 00:30:00 02:30:00 07:30:00 08:00:00 09:00:00 09:00:00 09:30:00
 [9] 10:00:00 10:30:00 11:00:00 13:00:00 14:00:00 14:00:00 16:00:00 16:00:00
[17] 16:00:00 17:30:00 18:00:00 18:00:00 18:30:00 19:00:00 20:30:00 21:00:00
[25] 21:30:00 22:00:00 22:30:00 23:00:00 23:30:00 23:30:00

$IQ
 [1] 100 104 101 101 102  78 105  93  78 116 106 104 110 110  96 100  87 102 111
[20]  94 106  89  88  92 104  95  99  92  76  97

$Height
 [1] 69 75 72 75 69 67 68 68 62 70 67 67 71 65 77 68 72 63 72 65 69 67 73 72 63
[26] 62 70 66 73 73

$Died
 [1] FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE
[13] FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
[25]  TRUE  TRUE FALSE FALSE  TRUE  TRUE

$Scoring
 [1]  0.53919137 -1.12704224 -0.24836976  1.69248009 -0.28944448 -0.26431602
 [7]  0.88675131 -0.39997264  0.18189530 -0.33675440 -0.64148517  0.98486839
[13] -0.73174989  0.67509885  1.10247947 -1.27738915 -2.61415664  1.79460633
[19]  0.16487598  0.53369362  0.29963975  1.07303042  1.02907669  0.52418339
[25]  0.25475364 -0.11338882  0.47259456 -0.01158515 -0.21004221  0.32445283

$ID
 [1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"

$Race
 [1] White     White     White     White     Black     White     Black    
 [8] Black     White     White     White     White     Hispanic  Hispanic 
[15] White     White     White     Black     White     White     Bi-Racial
[22] White     White     Black     White     White     White     Asian    
[29] Black     White    
Levels: White Hispanic Black Asian Bi-Racial Native Other Hawaiian

$Age
 [1] 12 13 10  8 13 11 13 12  8 12 11 12 13 10  9 14 13  9  9 12 12  8 12 10 10
[26] 14  9  9 11 11

$Gender
 [1] Male   Female Female Male   Male   Male   Male   Male   Female Female
[11] Female Male   Female Female Male   Male   Female Female Male   Female
[21] Male   Female Female Male   Female Female Male   Male   Female Female
Levels: Male Female

$Time
 [1] 01:30:00 03:00:00 03:30:00 05:30:00 07:30:00 07:30:00 08:00:00 08:30:00
 [9] 09:30:00 09:30:00 10:00:00 11:00:00 11:30:00 12:00:00 14:00:00 15:00:00
[17] 17:00:00 17:00:00 18:00:00 18:30:00 18:30:00 19:00:00 19:00:00 19:30:00
[25] 19:30:00 21:00:00 22:30:00 23:00:00 23:00:00 23:30:00

$IQ
 [1]  92 106  99 101 102  79 105  90 100 109  96 120  88  98 103  98 103 108 106
[20] 107 104  96  92  98  81 102  98 109 106 107

$Height
 [1] 63 54 34 45 59 70 53 59 58 39 60 49 53 57 59 35 42 54 50 48 34 24 49 49 67
[26] 35 44 44 57 66

$Died
 [1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE
[13]  TRUE  TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE  TRUE
[25] FALSE  TRUE  TRUE  TRUE FALSE  TRUE

$Scoring
 [1] -1.232226348 -1.479246378 -2.185782138  0.563635125 -0.054750534
 [6]  0.839581515 -0.080226374  0.491523848  0.188069023  0.167657686
[11]  0.713513268 -0.110457978  2.172222488 -0.532772388 -0.064280065
[16] -1.120664385  0.600972469  1.009069645  1.110132579  0.394346602
[21]  0.001880635 -1.965804758  0.221632754 -0.367381126 -0.644785879
[26]  0.010859134 -0.827375104  1.034000521 -1.897655993  0.225529267

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