我需要按列(不带零)获取丰度值,因此,我使用了一个空列表和一个循环(for循环)。当我在循环的第一行中删除[i]时,仅在总值(对象的总和)列中获得了所需的结果,但是在我学习编写它们的方式中,我仅获得了不希望的结果。
set.seed
df <- data.frame(Category = sample(LETTERS[1:10]),
Object = sample(letters[1:10]),
A = sample(0:20, 10, rep = TRUE),
B = sample(0:20, 10, rep = TRUE),
C = sample(0:20, 10, rep = TRUE))
sincero <- list()
for (i in colnames(df[ , 3:5])){
sincero[i] = df[df[ , i] != 0, ]
sincero
}
sincero