[R] Odp: A problem of is.list function

Petr PIKAL petr.pikal at precheza.cz
Fri Aug 5 11:45:07 CEST 2011


Hi
> 
> Hi all
> 
> I want to use function of is.list and is.data.frame in if-else 
statement,
> but I get a trouble. To replicate this trouble, I run codes like that:
> 
> > set.seed(123)
> > x <- rnorm(100)
> > x <- data.frame(matrix(x, 10, 10))
> > class(x)
> [1] "data.frame"
> > is.list(x)
> [1] TRUE
> > is.data.frame(x)
> [1] TRUE
> 
> > version
>                _
> platform       i386-pc-mingw32
> arch           i386
> os             mingw32
> system         i386, mingw32
> status
> major          2
> minor          13.1
> year           2011
> month          07
> day            08
> svn rev        56322
> language       R
> version.string R version 2.13.1 (2011-07-08)
> 
> 
> The class of x is data frame, but when I use is.list, I also get a TRUE
> result. Why does this happen?

R-intro document which shall be included in any installation tells you 
about data frame

6.3 Data frames
A data frame is a list with class "data.frame". There are restrictions on 
lists that may be made into data frames, namely 
The components must be vectors (numeric, character, or logical), factors, 
numeric matrices, lists, or other data frames. 
Matrices, lists, and data frames provide as many variables to the new data 
frame as they have columns, elements, or variables, respectively. 
Numeric vectors, logicals and factors are included as is, and character 
vectors are coerced to be factors, whose levels are the unique values 
appearing in the vector. 
Vector structures appearing as variables of the data frame must all have 
the same length, and matrix structures must all have the same row size. 

Regards
Petr


> 
> Lian Peng
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list