See below. On 1/9/07, Farrel Buchinsky <[EMAIL PROTECTED]> wrote: > You have assumed everything as I meant it. > I understand what is happening now. ls() simply creates a vector with > character elements and dim() sees each element as not having dimensions. The > critical part of what you have shown is the get(command) that turns what is > just a string into the dataframe or vector whose name is the string. The > other issue which you showed, and one that I have come across before is that > sapply and tapply and lapply cannot handle a function on a function. I would > have thought that I should get the same result from > > lapply(ls(),dim(get())) or something such as that.
The gsubfn package can do nearly that. Just preface the function of interest (in this case sapply) with fn$ and then you can write the function as a formula: > library(gsubfn) > fn$sapply(c("iris", "CO2"), ~ dim(get(x)), simplify = FALSE) $iris [1] 150 5 $CO2 [1] 84 5 > > But instead one has to create a function command within the lapply to handle > a dimension command upon a get command. > > > On 1/9/07, Barry Rowlingson <[EMAIL PROTECTED]> wrote: > > > > Farrel Buchinsky wrote: > > > Why will the following command not work > > > sapply(objects(),dim) > > > What does it say about the objects list? What does it say about the dim > > > command? > > > > > > Likewise, the following also does not work > > > all<-ls() > > > for (f in all) print(dim(f)) > > > > 'objects()' returns character strings - the names of objects - then > > the dim of the character strings are all NULL. > > > > I'll assume that's what you are getting at - you've not posted an > > example or the output you are getting or why it 'does not work'. > > > > Maybe you want this: > > > sapply(objects(),function(x){dim(get(x))}) > > $f > > NULL > > > > $m > > [1] 2 5 > > > > $x > > NULL > > > > $y > > [1] 5 2 > > > > - where m and y are matrices, f is a function, x is a scalar. > > > > Barry > > > > > > > -- > Farrel Buchinsky > Mobile: (412) 779-1073 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.