Re: [R] dimensions of a all objects

From: Farrel Buchinsky <>
Date: Tue 09 Jan 2007 - 15:16:14 GMT

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.

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 <> 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
> $m
> [1] 2 5
> $x
> $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]]

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Jan 10 02:30:29 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 09 Jan 2007 - 16:30:31 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.