I wrote the code below
miRNA.list <- c("let-7a-5p", "let-7a-1-3p", "let-7b-5p")
summary.df <- data.frame()
for (miRNA in miRNA.list) {
temp.name <- miRNA
temp.df <- df.mirna.pv %>%
filter(`temp.name` == "yes") %>%
summarise(downregulated = sum(str_count(status, "downregulated")),
upregulated = sum(str_count(status, "upregulated")),
all = n())
summary.df <- rbind(summary.df, temp.df)
}
to filter the following dataframe based on the "let-xxx" columns and then count number of up or downregulated genes;
print(df.mirna.pv)
let-7a-5p let-7a-1-3p let-7b-5p status
Xkr4 no yes no upregulated
Mrpl15 yes yes no downregulated
Lypla1 yes yes yes downregulated
Tcea1 no yes no not significant
However, for some reason, it cannot match the names in miRNA list with the column names, or at least I think this is the problem, as this is my output:
downregulated upregulated all
1 0 0 0
2 0 0 0
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
Any ideas what could be happening and how can I fix it?
You are mixing normal and programmatic use of
dplyr. Namely,filter(`temp.name` == "yes")is looking for a column named"temp.name", not a column that is indirectly referenced in the local variabletemp.name.I think this may be what you want?
You can remove
`not significant`if you don't need it.Data