Wilcoxon Test in a loop for a number of datasets at the same time

I have a question about whether i can do a Wilcoxon test in a loop for all the table generated.

Basically, i want to do a paired wilcoxon test between 2 variables for each dataset, and the 2 variables are in the same position(like xth and yth column) for every dataset.(For people who are familiar with Biology, in fact this is the RPKM values for like between control and treated sample for some repetitive elements) And i hope i can generate a table for the p-value from Wilcoxon test for each dataset.

I ready generated all the tables/dataset/dataframe using the below code and i think i want to do a Wilcoxon test for each dataset so i think i need to continue with the loop but i don't know how to do it:

for(i in 1:length(filter)){
  table_name=paste('table_', filter[i], sep="")
  print(table_name)
  assign(table_name, data[data$TE_Subfamily == filter[i]])

Usually for a single dataset, i will do the Wilcoxon test in this way:

(so basically the case is that i will get all the rows containing 'ABC' and do the Wilcoxon test between normal and cancer using RPKM value from the large dataset 'POGGAS')

wilcox_test_ABC<- POGGAS %>%
  filter(str_detect(Region_ID,'ABC'))

wilcox_test_ABC_treated <- c(wilcox_test_ABC$treated_rpkm)
wilcox_test_ABC_normal <- c(wilcox_test_ABC$normal_rpkm)

wilcox_test_ABC_dataframe <- data.frame(group=rep(c("wilcox_test_ABC_normal","wilcox_test_ABC_treated"),each=nrow(wilcox_test_ABC)),RPKM = c(wilcox_test_ABC_normal, wilcox_test_ABC_treated))

#each=x is to look at how mamy elements are there, can be replace by nrow(dataframe u want to look at)

before <- subset(wilcox_test_ABC_dataframe,  group == "wilcox_test_ABC_normal", RPKM,
                 drop = TRUE)

after <- subset(wilcox_test_ABC_dataframe,  group == "wilcox_test_ABC_treated", RPKM,
                 drop = TRUE)

library(PairedData)
pd <- paired(before, after)
plot(pd, type = "profile") + theme_bw()
res <- wilcox.test(before, after, paired = TRUE)

I'm sorry if i mention the term wrongly as i am a newbie in R and thank you so much for the help

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.