I'm sorry to ask you so many rudimentary questions.
Thank you very much for your help with the following questions.
Remove missing columns (or convert to 0)
Currently, based on various instructions, we are performing the following output: csv creation → input to R → Mann-whitney calculation → csv output.
Data<-read.csv("sample.csv", header=TRUE)
Data_long<-gather (Data, key=fac, value=value, factor_key=TRUE)
Data_long_rmNA<-drop_na(Data_long, value)
temp<-with(Data_long_rmNA, pairwise.wilcox.test(value, fac, exact=FALSE, p.adjust.method="none")$p.value
write.csv(temp, file="sample_result.csv", quote=F)
Currently, I am satisfied, but since there are many csv files to enter, it is troublesome to enter the name in each sample, so I tried the following.
i<- "sample"
Data<-read.csv(sprintf("%s.csv", i), header=TRUE)
Data_long<-gather (Data, key=fac, value=value, factor_key=TRUE)
Data_long_rmNA<-drop_na(Data_long, value)
temp<-with(Data_long_rmNA, pairwise.wilcox.test(value, fac, exact=FALSE, p.adjust.method="none")$p.value
write.csv(temp, file=sprintf("%s_result.csv", i), quote=F)
By the way, is it possible to automate this further?I think I can do it if I write it in For sentence.However, the name of the csv file you enter is not regular, so I'm having trouble.If the file name is 1, 2, 3..., I think I can do it with the For statement...
For example, if the file name is A4fg, Brtg, Huji, CVYh...
Data<-(A4fg, Brtg, Huji, CVYh...)
I'd like to write a code that says that I'm going to put the code like in the beginning and do it one by one.Of course, it would be helpful if you could print it as the file name_result.csv.
Thank you for your guidance.
r
Hope this helps!
#setwd("<absolute path of directory having all csv files>")
setwd("<absolute path to directory containing all affected CSV files>")
# Enumerate all CSV files in the above directory
# list all csv files in above directory
files<-list.files(pattern="\\.csv$")
for (fin1:length(files)) {
i<-gsub("(.*).csv", "\\1", files[f])
# <your code>
<Your Code>
}
© 2024 OneMinuteCode. All rights reserved.