[R] Weird problem with trying to change a variable

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Jan 17 10:21:02 CET 2004


On Sat, 17 Jan 2004, Damon Wischik wrote:

[Quoting me in reply to something else without the context not 
attribution.]

> > Lists?  Do you mean vectors?  Columns of dataframes are not supposed to be 
> > lists.
> 
> Ah. I've been using commands like
> 
> > x <- list(c(1,2,3),c(2,1),c(6,6,1))
> > y <- c("A","B","C")
> > data.frame(I(x),y)
>         x y
> 1 1, 2, 3 A
> 2    2, 1 B
> 3 6, 6, 1 C
> 
> This sort of object behaves pretty much as I'd expect it to (using R 1.8.0
> for Windows), though I've only made limited use. The x column has mode
> list but class AsIs. Is this a legitimate use? 

Yes.  That is not a `bare' list, but a class with a specific method.

> (The documentation tells me that as.data.frame is a generic method, with
> many implementations, including one for AsIs; and that the function I will
> accept any object. I haven't looked into the implementation.)

All you need is for the length to match.  It is possible to get bare lists
into data frames, but as.data.frame.list inserts each column separately
and if you do circumvent that (and I don't mean by I()) some strange
things can happen.  We don't guarantee not to break what currently works
in that area, either.

-- 
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




More information about the R-help mailing list