在我的数据框中,对于RowMeansCollapsed
相同的行,我想取RowStDev
和RowNamesLengthCollapsed
的平均值。这将生成仅具有唯一RowNamesLengthCollapsed
的输出数据帧。
> head(RowMeans_Names)
RowNamesCollapsed RowMeansCollapsed RowStDev RowNamesLengthCollapsed
1 GCATTGGTGGTTCAGTGGTAGAATTCTCGCCT 38.2083333333333 140.255174717683 32
2 AGGTTCCGGATAAGTAAGAGCC 3.5625 6.62977732419582 22
3 TCTTAACCCGGACCAGAAACTA 3.25 7.10226057415228 22
4 CTGACCTATGAATTGACAGCC 29.1875 110.206439061093 21
5 TACCCTGTAGAACCGAATTTGT 46.6041666666667 161.866772973895 22
6 GTTTCCGTAGTGTAGTGGTTATCACGTTCGCCT 41.96875 148.825680659234 33
答案 0 :(得分:2)
使用‹dplyr›,这是微不足道的:
RowMeans_Names %>%
group_by(RowNamesCollapsed) %>%
summarize(RowMeansCollapsed = mean(RowMeansCollapsed),
RowStDev = mean(RowStDev),
RowNamesLengthCollapsed = first(RowNamesLengthCollapsed))
答案 1 :(得分:1)
也许这可能对你有帮助。
df2 <- aggregate(cbind(RowMeansCollapsed, RowStDev) ~ RowNamesCollapsed, df, mean)