Dear R People: I want to get the class of all of the objects in my directory. I was trying: do.call(class,list=ls()) but got an "unused argument error". I'm sure it's simple, but I'm just not seeing it. Any help would be much appreciated. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com
On 19/03/2008, at 4:39 PM, Erin Hodgess wrote:> Dear R People: > > I want to get the class of all of the objects in my directory. > > I was trying: > > do.call(class,list=ls()) > > but got an "unused argument error". > > I'm sure it's simple, but I'm just not seeing it. > > Any help would be much appreciated. > > Sincerely, > ErinToo easy!!! sapply(ls(),function(x){class(get(x))}) cheers, Rolf ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
On Mar 18, 2008, at 11:44 PM, Rolf Turner wrote:> > On 19/03/2008, at 4:39 PM, Erin Hodgess wrote: > >> do.call(class,list=ls()) > > sapply(ls(),function(x){class(get(x))})or, in case you want to save some typing: eapply(globalenv(), class) b
Try: eapply(.GlobalEnv, class) or perhaps unlist(eapply(.GlobalEnv, class)) or str(eapply(.GlobalEnv, class)) On Tue, Mar 18, 2008 at 11:39 PM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:> Dear R People: > > I want to get the class of all of the objects in my directory. > > I was trying: > > do.call(class,list=ls()) > > but got an "unused argument error". > > I'm sure it's simple, but I'm just not seeing it. > > Any help would be much appreciated. > > Sincerely, > Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodgess at gmail.com > > ______________________________________________ > R-help at r-project.org 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. >
Correction to my thinko sapply(ls(), function(x) class(get(x)))
Rolf Turner <r.turner at auckland.ac.nz> wrote in news:72856D72-D960-48ED-AA77-ABD353548C08 at auckland.ac.nz:> > On 19/03/2008, at 4:39 PM, Erin Hodgess wrote: > >> Dear R People: >> >> I want to get the class of all of the objects in my directory. >>> > Too easy!!! > > sapply(ls(),function(x){class(get(x))}) >Thank you, Rolf. That supplied the needed index to the question I struggled with yesterday: How to get a list of only my dataframes: ls()[sapply(ls(),function(x){class(get(x))}) == "data.frame"] -- David Winsemius
> library(R.oo) > example(data.frame) > example(matrix) > example(iris) > ll()member data.class dimension objectSize 1 author character 1 120 2 d data.frame c(10,3) 1136 3 d.0 data.frame c(0,3) 824 4 d0 data.frame c(10,0) 320 5 d00 data.frame c(0,0) 312 6 dd data.frame c(10,4) 1680 7 dni3 list 3 392 8 ii data.frame c(150,5) 6424 9 L3 character 3 136 10 mdat matrix c(2,3) 480> subset(ll(), data.class == "data.frame")member data.class dimension objectSize 2 d data.frame c(10,3) 1136 3 d.0 data.frame c(0,3) 824 4 d0 data.frame c(10,0) 320 5 d00 data.frame c(0,0) 312 6 dd data.frame c(10,4) 1680 8 ii data.frame c(150,5) 6424> subset(ll(), data.class %in% c("character", "matrix") & objectSize > 125)member data.class dimension objectSize 9 L3 character 3 136 10 mdat matrix c(2,3) 480 You can also add your own column annotations given some rules of yours by passing special functions. See help(ll) for more details. /Henrik On Wed, Mar 19, 2008 at 7:50 AM, David Winsemius <dwinsemius at comcast.net> wrote:> Rolf Turner <r.turner at auckland.ac.nz> wrote in > news:72856D72-D960-48ED-AA77-ABD353548C08 at auckland.ac.nz: > > > > > > On 19/03/2008, at 4:39 PM, Erin Hodgess wrote: > > > >> Dear R People: > >> > >> I want to get the class of all of the objects in my directory. > >> > > > > > > Too easy!!! > > > > sapply(ls(),function(x){class(get(x))}) > > > > > Thank you, Rolf. That supplied the needed index to the question I > struggled with yesterday: How to get a list of only my dataframes: > > ls()[sapply(ls(),function(x){class(get(x))}) == "data.frame"] > > -- > David Winsemius > > > > ______________________________________________ > R-help at r-project.org 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. >