list_of_files <- list.files('C1_to_C6/',pattern = '\.txt$', full.names = TRUE)
#Further arguments to read.csv can be passed in ...
all_csv <- lapply(list_of_files,read.csv)
#Set the name of each list element to its
names(all_csv) <- gsub(".txt","",
list.files("C1_to_C6/",full.names = FALSE),
fixed = TRUE)
The above code reads all my files into the list.
Now i have a list of data frame as such
list_of_files
[1] "C1_to_C6//C1_C2_contrast.txt" "C1_to_C6//C1_C3_contrast.txt" "C1_to_C6//C1_C4_contrast.txt" "C1_to_C6//C1_C5_contrast.txt"
[5] "C1_to_C6//C1_C6_contrast.txt" "C1_to_C6//C2_C3_contrast.txt" "C1_to_C6//C2_C4_contrast.txt" "C1_to_C6//C2_C5_contrast.txt"
[9] "C1_to_C6//C2_C6_contrast.txt" "C1_to_C6//C3_C4_contrast.txt" "C1_to_C6//C3_C5_contrast.txt" "C1_to_C6//C4_C5_contrast.txt"
[13] "C1_to_C6//C4_C6_contrast.txt" "C1_to_C6//C5_C6_contrast.txt" "C1_to_C6//C6_C5_contrast.txt"
The genral structure of my data frame is like this, I was not able to put the dput
of the dataframe as due to some issue whenever i do dput(head(a,5)) the whole data comes up
ab <- read.table(text = "
gene baseMean log2FoldChange lfcSE stat pvalue padj
ENSMUSG00000033845 1104.8298 0.30429069 0.06539399 4.6531907 3.268377e-06 4.019525e-05
ENSMUSG00000025903 848.4143 0.13443658 0.07048958 1.9071837 5.649680e-02 1.440507e-01
ENSMUSG00000033813 510.3910 0.05108741 0.09050085 0.5644965 5.724163e-01 7.234561e-01
ENSMUSG00000033793 1569.8826 0.04845688 0.06197695 0.7818531 4.343009e-01 6.049862e-01
ENSMUSG00000025907 1430.4057 -0.32015475 0.06772883 -4.7270084 2.278518e-06 2.924837e-05", header = TRUE)
To filter the single dataframe i do this.
sig_table_hw_oe <- filter(a, padj < 0.05 & abs(log2FoldChange) > 1)
UP_DOWN <- mutate(sig_table_hw_oe, UP_DOWN = ifelse(log2FoldChange > 1, "UP", "DOWN"))
Now i would like to do the same for the list of dataframe which i do for the single dataframe how to do it?
The output for single dataframe would be like this
gene baseMean log2FoldChange lfcSE stat pvalue padj UP_DOWN
ENSMUSG00000103509 18.57491 -3.194136 0.7446761 -4.289297 1.792399e-05 1.812452e-04 DOWN
ENSMUSG00000104358 22.75726 -1.448193 0.5525529 -2.620913 8.769460e-03 3.439516e-02 DOWN
ENSMUSG00000026069 525.12341 1.083185 0.1057836 10.239630 1.317393e-24 2.045214e-22 UP
This is what i want to achive for my list of data-frame and write them as output into a file.
UPDATE
Im able to apply the condition
abc <- lapply(all_csv, function(x) filter(x, padj < 0.05 & abs(log2FoldChange) > 1))
The above one filters my list of DF.
But when i try to label it using the below code I get the error as such
abd <- lapply(abc, function(x) filter(x, UP_DOWN = ifelse(log2FoldChange > 1, "UP", "DOWN")))
Error: Problem with `filter()` input `..1`.
x Input `..1` is named.
? This usually means that you've used `=` instead of `==`.
? Did you mean `UP_DOWN == ifelse(log2FoldChange > 1, "UP", "DOWN")`?
Run `rlang::last_error()` to see where the error occurred.
Any suggestion how to do the above would be really appreciated.
question from:
https://stackoverflow.com/questions/65861249/label-list-of-data-frame-based-on-filtering-criteria