I’ve imported multiple files read.table and named each as file1, file2, file3,…
I’ve put all of the data.frames (read.table files) into a list:
ClassFilter <- function(x) inherits(get(x), 'data.frame' )
Objs <- Filter( ClassFilter, ls() )
Now I want to call each data.frame (e.g. file1) and do a column mean:
for(x in 1:NumberOfFiles){
mean[NumberOfFiles:400] <- apply(Objs[[x]],2,mean)
}
The problem is Objs[[x]] is giving me an error “Error in apply(Objs[[x]], 2, mean) : dim(X) must have a positive length” as the element in the list is not pointing to the data.frame. Anyone know how I can make the list element point to the data.frame from which the list was created initially? Thank you
Objscontains the names of thedata.framevariables, so you must get the variable first usingget()function:or if you prefer you can also “evaluate” the variable name:
Also, as correctly pointed out by @SeñorO you should give a different name to
meanobject to avoid conflicts with the function mean.