我是一名有用的助手,可以为您翻译文本。
如果我在前6行上执行dcast,我会得到以下结果:
如果我对所有行进行dcast,我会得到:
我有以下情况。考虑以下数据框:
mymatrix <- as.data.frame(matrix(data = 0, nrow = 7, ncol = 4))
colnames(mymatrix) <- c("Patient", "marker", "Number", "Visit")
mymatrix[,1] <- c("B1","B1","C1","C1","D1","D1","D1")
mymatrix[,2] <- c("A","A","A","A","A","A","A")
mymatrix[,3] <- c(1,0,0,15,1,2,13)
mymatrix[,4] <- c("baseline","followup","baseline","followup","baseline","followup","followup")
> mymatrix
Patient marker Number Visit
1 B1 A 1 baseline
2 B1 A 0 followup
3 C1 A 0 baseline
4 C1 A 15 followup
5 D1 A 1 baseline
6 D1 A 2 followup
7 D1 A 13 followup
如果我在前6行上执行dcast,我会得到以下结果:
> dcast(mymatrix[1:6,], Patient +marker~Visit, value.var = "Number")
Patient marker baseline followup
1 B1 A 1 0
2 C1 A 0 15
3 D1 A 1 2
如果我对所有行进行dcast,我会得到:
> dcast(mymatrix, Patient +marker~Visit, value.var = "Number")
Aggregation function missing: defaulting to length
Patient marker baseline followup
1 B1 A 1 1
2 C1 A 1 1
3 D1 A 1 2
有没有一种方法,而不是默认长度,它可以添加第二个跟进列?因此数据将显示如下:
Patient marker baseline followup.1 followup.2
1 B1 A 1 0 NA
2 C1 A 0 15 NA
3 D1 A 1 2 13
谢谢!
followup.2
的所有列都使用length
,而followup.2
是每个组中的第二个followup
值?那对我来说没有任何意义。您是指想将followup.2
添加到您的第一个输出中吗? - David Arenburg