I have some data.frames
dat1=read.table...
dat2=read.table...
dat3=read.table...
And I would to count the rows for each data set. So
the names are saved like this (cannot “change” it) vector=c(“dat1″,”dat2”,”dat3…)
p <- vector(numeric, length=1:length(dat))
counting <- function(x) {for (i in 1:x){
p[i]<-nrow(dat[i])}
return(p)
}
This is not working because the input for nrow is a character, but i need integer(?) or?
Thx for help
You can use
getfor this, but be careful! Instead reading the tables at alistis the R-ish way:Then you have all the conveniences of
lapplyand theapplyfamily at your disposal, e.g.:The solution using
get(alsovectoris a bad variable name since its a very important function):Your method fails since there is no object called
datto index into. Thefor loopcould look like:But that technique is poor form for lotsa reasons…