Dear R People:
Here is a really goofy question.
I have some objects which have 2 classes: data.frame and ucr.
Also, the classes will always be in that order.
I have tried all sorts of things, but to no avail.
listucrModels <- function(envir=.GlobalEnv, ...) {
objects <- ls(envir=envir, ...)
if (length(objects) == 0) NULL
else objects[sapply(objects,
function(.x) "ucr"= (class(eval(parse(text=.x),
envir=envir))[2]))]
}
> listucrModels()
[1] NA NA NA NA NA NA NA NA
[9] NA NA NA NA NA "jan.df" NA NA
[17] NA NA NA NA NA NA NA NA
[25] NA NA NA NA NA NA NA
NA>
Since most of them do not have the second class attribute.
How do I get rid of the NA's and just get a list, please?
Thanks,
Erin
--
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodgess at gmail.com
names(lapply(.GlobalEnv, function(x) inherits(x, "ucr"))) HTH, Josh On Wed, Oct 12, 2011 at 12:46 AM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:> Dear R People: > > Here is a really goofy question. > > I have some objects which have 2 classes: data.frame and ucr. > > Also, the classes will always be in that order. > > I have tried all sorts of things, but to no avail. > > listucrModels <- function(envir=.GlobalEnv, ...) { > ? ?objects <- ls(envir=envir, ...) > ? ?if (length(objects) == 0) NULL > ? ?else objects[sapply(objects, > ? ? ? function(.x) ?"ucr"=> ? ? ? (class(eval(parse(text=.x), envir=envir))[2]))] > ? ?} > >> listucrModels() > ?[1] NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA > ?[9] NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? "jan.df" NA ? ? ? NA > [17] NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA > [25] NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA ? ? ? NA >> > Since most of them do not have the second class attribute. > > How do I get rid of the NA's and just get a list, please? > > Thanks, > 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/
On Wed, Oct 12, 2011 at 8:46 AM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:> Dear R People: > > Here is a really goofy question. > > I have some objects which have 2 classes: data.frame and ucr. > > Also, the classes will always be in that order. > > I have tried all sorts of things, but to no avail. > > listucrModels <- function(envir=.GlobalEnv, ...) { > ? ?objects <- ls(envir=envir, ...) > ? ?if (length(objects) == 0) NULL > ? ?else objects[sapply(objects, > ? ? ? function(.x) ?"ucr"=> ? ? ? (class(eval(parse(text=.x), envir=envir))[2]))] > ? ?} >Can you get away with just testing inherits(x,"ucr") or "ucr" %in% class(x)? Or do you really have to test that "ucr" is the second element? Do you have objects of class "ucr" that aren't also of class "data.frame"?