s*******d 发帖数: 132 | 1 I have an id variable, and hundreds of covariates var1- var100.
There are some id are the same with each other. For these rows with the same
id, I need to calculate the mean for var1 - var100, respectively.
How to do this in R? Thanks. | d********t 发帖数: 837 | 2 ddply in the plyr package. | D******n 发帖数: 2836 | 3 aggregate
same
【在 s*******d 的大作中提到】 : I have an id variable, and hundreds of covariates var1- var100. : There are some id are the same with each other. For these rows with the same : id, I need to calculate the mean for var1 - var100, respectively. : How to do this in R? Thanks.
| s*******d 发帖数: 132 | 4 Thanks.
【在 D******n 的大作中提到】 : aggregate : : same
| S******y 发帖数: 1123 | 5 Compute group means in R
There are several ways to compute means by groups in R.
For example, if you would like to computer average score by gender, you can
achieve that in one of the following three ways -
1) plotmeans(score ~ gender)
will plot group means and confidence intervals.
(it requires gplot package)
2) aggregate(score, list(gender_class = gender), mean)
will split the data into subsets, computes summary statistics for each
3) tmp=split(score, gender)
sapply(tmp, mean)
‘split’ divides the data into groups
'sapply' applies mean function to a list of elements |
|