[R] getting list of data.frame names

Joshua Wiley jwiley.psych at gmail.com
Sun Oct 2 05:46:10 CEST 2011


Hi Erin,

Try this: names(which(sapply(.GlobalEnv, is.data.frame)))

Cheers,

Josh

On Sat, Oct 1, 2011 at 8:37 PM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:
> Dear R People:
>
> This is probably a very simple question.  I know that if I want to get
> a list of the classes of the objects in the workspace, I can do this:
>
>> sapply(ls(), function(x)class(get(x)))
>           a        a1.df            b            d
>      "list" "data.frame"    "integer"    "numeric"
>
> Now I want to get just the data frames.
>> sapply(ls(), function(x)class(get(x))=="data.frame")
>    a a1.df     b     d
> FALSE  TRUE FALSE FALSE
>
> However, I would like the names of the data frames, rather than the
> True/False for the objects.
>
> I've been trying all sorts of combinations/permutations with no success.
>
> Any suggestions would be much appreciated.
>
> Thanks,
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list