Hi, I am writing a generic function and need to check if an arg is a data frame or not. I could use is.null(dim(x)) to get what i want. But i want to know if there is a function which can tell me whether it is a list, a numeric vector, a data frame, a factor and so on. Can R do that? thanks. -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. "Did you always know?" "No, I did not. But I believed..." ---Matrix III
check class() but if all you want is to test whether it's a data.frame or not: is.data.frame() b On Nov 14, 2006, at 3:07 PM, Weiwei Shi wrote:> Hi, > I am writing a generic function and need to check if an arg is a data > frame or not. I could use > is.null(dim(x)) to get what i want. But i want to know if there is a > function which can tell me whether it is a list, a numeric vector, a > data frame, a factor and so on. Can R do that? > > thanks. > > -- > Weiwei Shi, Ph.D > Research Scientist > GeneGO, Inc. > > "Did you always know?" > "No, I did not. But I believed..." > ---Matrix III > > ______________________________________________ > R-help at 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.
On Tue, 14 Nov 2006, Weiwei Shi wrote:> Hi, > I am writing a generic function and need to check if an arg is a data > frame or not.?is.data.frame> I could use is.null(dim(x)) to get what i want.In which case you would fail. Arrays and many other objects have non-NULL dims.> But i want to know if there is a > function which can tell me whether it is a list, a numeric vector, a > data frame, a factor and so on. Can R do that?Yes. ?typeof, ?class, ?str, ?inherits ... and please do study 'An Introduction to R' (belatedly). You do seem to be asking almost daily for people to read the documentation for you. Please try install.packages("fortunes"); library(fortunes); fortune("WTFM") -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595