我有一个这样的dataframe:
df <- data.frame(
sample1 = c(0, 1, 2, 0, 2, 1),
sample2 = c(0.3, 3, 2, 0.4, 2, 3),
sample3 = c(0.2, 1, 3, 0.1, 3, 3),
sample4 = c(0.4, 2, 4, 0.3, 1, 1),
sample5 = c(0.1, 2, 4, 0.2, 5, 3),
sample6 = c(0.2, 3, 1, 0.1, 6, 3),
sample7 = c(0.2, 1, 1, 0.4, 1, 1)
)
在这个df中定义的组:
groups <- data.frame(
samples = c("sample1", "sample2", "sample3", "sample4", "sample5", "sample6", "sample7"),
groups = c("group1", "group1", "group1", "group2", "group2", "group3", "group3")
)
使用R,我想只保留至少一个组中的总和大于0.5的行,因此结果df将是:
sample1 sample2 sample3 sample4 sample5 sample6 sample7
2 1 3 1 2 2 3 1
3 2 2 3 4 4 1 1
5 2 2 3 1 5 6 1
6 1 3 3 1 3 3 1
2条答案
按热度按时间4szc88ey1#
lnvxswe22#
以下是
tidyverse
版本:注意,只有一行(例如满足标准的行4):