简体   繁体   English

使用 Tidyr 创建数据集

[英]Create Dataset using Tidyr

I typically create my dataset using the following code, where I sample individual estimates from the pkpd dataset (data_pkpd):我通常使用以下代码创建我的数据集,其中我从 pkpd 数据集 (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.但是, mutate_random 是 dmutate package 的一部分,我无法将其用于当前分析。 Is there any alternative approach to create individual dataset with sampling using tidyr package?是否有任何替代方法可以使用 tidyr package 创建带有采样的单个数据集?

Thank you!谢谢!

Are you just wanting to create a random dataframe?您只是想创建一个随机的 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.第一个数字 (5) 是列数,范围 (0:100) 是样本范围,也就是可能的数字,最后一个数字 (10) 是行数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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