简体   繁体   中英

Create Dataset using Tidyr

I typically create my dataset using the following code, where I sample individual estimates from the pkpd dataset (data_pkpd):

NSIM=100
idata_SIM0<- data.frame(expand.idata(ID=c(1:nsim)) %>%
                          mutate(GRP=1) %>%
                          # mutate(WT=rep(each=200,seq(41,120,1))) %>%
                          mutate_random(CL ~ sample(data_pkpd$ICL, size=nsim, replace = TRUE))%>%
                          mutate_random(Q ~ sample(data_pkpd$IQ, size=nsim, replace = TRUE))%>%
                          mutate_random(V2 ~ sample(data_pkpd$IV2, size=nsim, replace = TRUE))%>%
                          mutate_random(V3 ~ sample(data_pkpd$IV3, size=nsim, replace = TRUE))%>%
                          mutate_random(V7 ~ sample(data_pkpd$IV7, size=nsim, replace = TRUE))%>%
                          mutate_random(Q2 ~ sample(data_pkpd$IQ2, size=nsim, replace = TRUE))%>%
                          mutate_random(KA ~ sample(data_pkpd$IKA, size=nsim, replace = TRUE))%>%
                          mutate_random(F1 ~ sample(data_pkpd$IF1, size=nsim, replace = TRUE))%>%
                          mutate_random(BL_PD ~ sample(data_pkpd$BL_PD, size=nsim, replace = TRUE))%>%
                          mutate(time=0)) 

However, mutate_random is a part of dmutate package and I am unable to use it for the current analysis. Is there any alternative approach to create individual dataset with sampling using tidyr package?

Thank you!

Are you just wanting to create a random dataframe? If so, you can try

data.frame(replicate(5,sample(0:100,10,rep=TRUE)))

The first number (5) is the number of columns, the range (0:100) is the sample range aka the possible numbers, the last number (10) is the number of rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM