Trying to get the colnames of columns which totals are > 0. I have tried
df[sapply(df, function(x) any(x > 0))]
but this gives me the actual numeric value. I then tried
names(df)[colSums(df)>0]
but received a NULL. Here is an example of my df where I would expect the output of "SRR960396" and "SRR960403".
> dput(df)
structure(c(14, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0), dim = 4:3, dimnames = list(
c("27b1da20c7a5364614a540521d5e38c0", "bd60888ac07bff9651845c6f6aca4fa8",
"e7474b1fd688aa54814538b69a56d202", "85907e71eb899b7edce9bf8d23746413"
), c("SRR960396", "SRR960402", "SRR960403")))
You should be aware that
dfis NOT adata.framebut amatrix, i.e.,so
colnames(df), instead ofnames, should be used to fetch the column names.A workaround is using
colSums+whichto locate the columns that have positive values, e.g.,