7.8 Random Dataset

20200421 Using wakefield::r_data_frame() it is straightforward to create simple random data datasets. More sophisticated sampling can be used if required though extra work is required to get correlated distributions across variables when looking to most accurately match some real world data. Nonetheless, creating random data quickly is the forte of wakefield (Rinker 2026).

library(wakefield)    # Generate random datasets.

nobs <- 100 # Number of observatios.

r_data_frame(n=nobs,
             id=id_factor,
             givennames=name,
             surname=name,
             dob=dob(start=Sys.Date()-365*100, k=365*99),
             sex=sex,
             phone=r_sample(x=400000000:499999999),
             diabetes=answer,
             result=r_sample_factor(x=c("pending", "positive", "negative")),
             previous=answer(prob=c(0.8,0.2)),
             bps=r_sample(90:135),
             temp=normal(36.3, 1.2),
             gcs=r_sample(3:15, prob=c(rep(0.01, 12), 0.88)),
             crp=normal(2.5, 2, min=0, max=200)) ->
random_ds

glimpse(random_ds)
## Rows: 100
## Columns: 13
## $ id         <fct> 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012,…
## $ givennames <chr> "Diolinda", "Dorthey", "Mateusz", "Luisangel", "Jotaro", "B…
## $ surname    <chr> "Darhyl", "Hemal", "Eibhlin", "Adarrius", "Lynnleigh", "Jen…
## $ dob        <date> 1971-02-12, 1950-02-10, 1949-09-19, 1974-03-29, 1926-10-26…
## $ sex        <fct> Male, Female, Male, Male, Male, Male, Female, Female, Male,…
## $ phone      <int> 481766386, 427617615, 485777285, 477359768, 426157255, 4162…
## $ diabetes   <fct> Yes, Yes, No, No, Yes, Yes, Yes, Yes, No, No, No, Yes, Yes,…
## $ result     <fct> pending, positive, positive, negative, negative, positive, …
## $ previous   <fct> No, No, No, No, No, No, No, Yes, Yes, No, No, No, No, No, N…
## $ bps        <int> 127, 132, 102, 135, 125, 132, 93, 124, 114, 121, 104, 97, 1…
## $ temp       <dbl> 35.43511, 36.76718, 37.12904, 34.62847, 34.62147, 34.96716,…
## $ gcs        <int> 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 6, 15, 15, 15, …
## $ crp        <dbl> 4.0827075, 2.4341900, 1.3941507, 3.7248325, 4.6968716, 3.46…

References

———. 2026. Wakefield: Generate Random Data Sets. https://github.com/trinker/wakefield.


If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0