>C1<-c(3,2,4,4,5)
> C2<-c(3,7,3,4,5)
> C3<-c(5,4,3,6,3)
> DF<-data.frame(ID=c("A","B","C","D","E"),
C1=C1,C2=C2,C3=C3)
> DF
ID C1 C2 C3
1 A 3 3 5
2 B 2 7 4
3 C 4 3 3
4 D 4 4 6
5 E 5 5 3
计算每行的均值
> data.frame(ID=DF[,1], Means=rowMeans(DF[,-1]))
ID Means
1 A 3.666667
2 B 4.333333
3 C 3.333333
4 D 4.666667
5 E 4.333333
来源:https://stackoverflow.com/questions/10945703/calculate-row-means-on-subset-of-columns
网友评论