I made a function that takes a dataframe as argument, and creates two dataframes in output according to a threshold value of one of the columns. These 2 output dataframes are named according to the original input dataframe.
spliteOverUnder <- function(res){
  nm <-deparse(substitute(res))
  assign(paste(nm,"_Overexpr", sep=""), res[which(as.numeric(as.character(res$log2FoldChange)) > 1),], pos=1)
  assign(paste(nm,"_Underexpr", sep=""), res[which(as.numeric(as.character(res$log2FoldChange)) < -1),], pos=1)
}
The function works correctly. I would like to use a loop on this function so that each of my dataframes gives 2 dataframes according to my criteria, so I created a list that contains my dataframes:
listRes <- list(DJ21_T0, DJ24_T0, DJ29_T0, DJ32_T0,
                DJ24_DJ21, DJ29_DJ21, DJ32_DJ21,
                DJ21_DJ24, DJ29_DJ24, DJ32_DJ24,
                DJ21_DJ29, DJ24_DJ29, DJ32_DJ29,
                DJ21_DJ32, DJ24_DJ32, DJ29_DJ32,
                Rec2_T0, Rec6_T0, Rec9_T0,
                Rec2_DJ32, Rec6_DJ32, Rec9_DJ32,
                Rec6_Rec2, Rec9_Rec2,
                Rec2_Rec6, Rec9_Rec6,
                Rec2_Rec9, Rec6_Rec9)
and used the following code:
for (i in 1:length(listRes)){
  spliteOverUnder(listRes[[i]])
}
But this one returns me the objects listRes[[i]]_Overexpr and listRec[[i]]Underexpr
I encounter the same problem when I do the loop like this:
for (i in listRes){
  spliteOverUnder(i)
}
Which gives me the objects i_Overexpr and i_Underexpr.
lapply(listRes, spliteOverUnder) doesn't work either...
How to loop correctly my function and get the objects corresponding to my dataframes ? (DJ21_T0_Overexpr, DJ21_T0_Underexpr, DJ24_T0_Overexpr, DJ24_T0_Underexpr, ... , Rec6_Rec9_Overexpr, Rec6_Rec9_Underexpr)
I think the trick deparse(substitute(res)) used in my function is problematic, giving the created objects the name i or listRes[[i]] rather than giving the name of the dataframe at position i in my listRes dataframe list.
Any help is welcome.
Thanks
 
    