I am new in the dplyr world - so sorry if the question might sound simple,
basically, I am interested in calculating the number of entries that are larger than 0.5 for each column. If they are lower than 0.5 I consider them as zero. I don't mind having a vector, that stores this number.
here is the example
messy <- data.frame(samples = c("s1", "s2", "s3", "s4"),
o1 = c(0.5, 0.7, 0.8, 0.6),
o2 = c(0.2, 0.8, 0.8, 0.1),
o3 = c(0.9, 0.2, 0.0, 0.1),
o4 = c(0.1, 0.6, 0.4, 0.4))
bb <- gather(messy, otu, counts, o1:o4)
bb %>% filter(counts > 0.5) %>% group_by(otu) %>% summarize(fre=n())
bb$fre/4
** update,
I believe the code in the example is what I wanted to have.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…