再現可能、欠損値ありのサンプルデータをRで作成する方法

Reference - https://twitter.com/Rbloggers/status/662350005315878912
Script
if (!require("pacman")) install.packages("pacman")
pacman::p_load_gh("trinker/wakefield")
pacman::p_load(dplyr, tidyr, ggplot2)
variables()#用意されている変数
variables("list")#変数のタイプ
sampleData<-r_data_frame(n=100,
  id,
  age(x=20:120),#レンジ設定
  sex,
  'deviation'=round(rnorm(50,sd=10,mean=50)),#自作変数追加可能  
  'old-school'=valid,#自作変数追加可能
  birth,
  race,
  eye,
  dna,
  hair,
  religion,
  likert_5
) %>% r_na(prob=.1)#dデータ欠損値
class(sampleData)
str(sampleData)
head(sampleData)
tail(sampleData)
Result

> variables()#用意されている変数
 [1] "age"              "animal"           "answer"           "area"             "birth"            "car"              "children"         "coin"            
 [9] "color"            "date_stamp"       "death"            "dice"             "died"             "dna"              "dob"              "dummy"           
[17] "education"        "ela"              "employment"       "eye"              "gender"           "gender_inclusive" "gpa"              "grade"           
[25] "grade_letter"     "grade_level"      "group"            "hair"             "height"           "height_cm"        "height_in"        "income"          
[33] "internet_browser" "iq"               "language"         "level"            "likert"           "likert_5"         "likert_7"         "lorem_ipsum"     
[41] "lower"            "lower_factor"     "marital"          "math"             "military"         "month"            "name"             "normal"          
[49] "normal_round"     "paragraph"        "pet"              "political"        "primary"          "race"             "religion"         "sat"             
[57] "sentence"         "sex"              "sex_inclusive"    "smokes"           "speed"            "speed_kph"        "speed_mph"        "state"           
[65] "string"           "upper"            "upper_factor"     "valid"            "year"             "zip_code"        

> variables("list")#変数のタイプ
$character
[1] "lorem_ipsum" "lower"       "name"        "paragraph"   "sentence"    "string"      "upper"       "zip_code"   

$date
[1] "birth"      "date_stamp" "dob"       

$factor
 [1] "animal"           "answer"           "area"             "car"              "coin"             "color"            "dna"              "education"       
 [9] "employment"       "eye"              "gender"           "gender_inclusive" "grade_level"      "group"            "hair"             "internet_browser"
[17] "language"         "lower_factor"     "marital"          "military"         "month"            "pet"              "political"        "primary"         
[25] "race"             "religion"         "sex"              "sex_inclusive"    "state"            "upper_factor"    

$integer
[1] "age"      "children" "dice"     "ela"      "level"    "math"     "year"    

$logical
[1] "death"  "died"   "smokes" "valid" 

$numeric
 [1] "dummy"        "gpa"          "grade"        "height"       "height_cm"    "height_in"    "income"       "iq"           "normal"       "normal_round"
[11] "sat"          "speed"        "speed_kph"    "speed_mph"   

$`ordered factor`
[1] "grade_letter" "likert"       "likert_5"     "likert_7"    

> class(sampleData)
[1] "tbl_df"     "tbl"        "data.frame"

> str(sampleData)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	100 obs. of  12 variables:
 $ ID        : chr  "001" "002" "003" "004" ...
 $ Age       : int  85 29 117 105 NA 95 33 29 35 33 ...
 $ Sex       : Factor w/ 2 levels "Male","Female": 2 2 2 1 2 NA 2 2 2 2 ...
 $ deviation : num  44 59 59 60 39 53 67 71 45 40 ...
 $ old-school: logi  FALSE TRUE TRUE TRUE TRUE FALSE ...
 $ Birth     : Date, format: "2001-06-15" "2002-11-12" "2001-11-22" "2002-04-23" ...
 $ Race      : Factor w/ 8 levels "White","Hispanic",..: 1 1 1 1 1 3 1 2 2 1 ...
 $ Eye       : Factor w/ 5 levels "Brown","Blue",..: 1 1 1 3 1 1 1 2 1 2 ...
 $ DNA       : Factor w/ 4 levels "Guanine","Adenine",..: 3 4 3 4 3 2 4 NA 1 3 ...
 $ hair      : Factor w/ 4 levels "Brown","Black",..: 4 2 NA 1 1 2 1 1 3 1 ...
 $ Religion  : Factor w/ 8 levels "Christian","Muslim",..: 3 1 1 NA 1 4 NA 3 3 NA ...
 $ Likert    : Ord.factor w/ 5 levels "Strongly Disagree"<..: 2 2 5 3 2 NA 3 NA 5 4 ...

> head(sampleData)
Source: local data frame [6 x 12]

     ID   Age    Sex deviation old-school      Birth   Race    Eye      DNA   hair  Religion          Likert
  (chr) (int) (fctr)     (dbl)      (lgl)     (date) (fctr) (fctr)   (fctr) (fctr)    (fctr)          (fctr)
1   001    85 Female        44      FALSE 2001-06-15  White  Brown  Thymine    Red      None        Disagree
2   002    29 Female        59       TRUE 2002-11-12  White  Brown Cytosine  Black Christian        Disagree
3   003   117 Female        59       TRUE 2001-11-22  White  Brown  Thymine     NA Christian Strongly Agree 
4   004   105   Male        60       TRUE 2002-04-23  White  Green Cytosine  Brown        NA         Neutral
5   005    NA Female        39       TRUE 2002-01-19  White  Brown  Thymine  Brown Christian        Disagree
6   006    95     NA        53      FALSE 2001-01-05  Black  Brown  Adenine  Black     Hindu              NA

> tail(sampleData)
Source: local data frame [6 x 12]

     ID   Age    Sex deviation old-school      Birth   Race    Eye      DNA   hair  Religion            Likert
  (chr) (int) (fctr)     (dbl)      (lgl)     (date) (fctr) (fctr)   (fctr) (fctr)    (fctr)            (fctr)
1   095    92     NA        64       TRUE 2002-01-10  White   Blue  Adenine  Brown    Muslim           Neutral
2   096    81     NA        NA       TRUE 2002-03-01  White   Blue  Thymine  Brown    Muslim                NA
3   097    33 Female        44       TRUE 2001-10-15  White  Green Cytosine Blonde        NA             Agree
4   098    26   Male        32       TRUE 2002-05-20  White   Blue  Thymine Blonde        NA   Strongly Agree 
5   099    97   Male        39      FALSE 2001-01-24  Asian  Brown  Guanine  Black Christian             Agree
6   100    70 Female        41      FALSE 2001-12-23  White  Brown Cytosine     NA Christian Strongly Disagree