[R] Data.frames : difference between x$a and x[, "a"] ? - How set new values on x$a with a as variable ?

Hadley Wickham hadley at rice.edu
Fri Sep 10 16:46:11 CEST 2010


>>> I think this is a really bad idea. data.frames are not meant to be
>>> used in this way. Why not use a list of lists?
>>
>> It can be very convenient, but I suspect the original poster is
>> confused about the different between vectors and lists.
>
> I wouldn't be surprised if someone were confused, since my reading of some
> (but not all) of the help documents has led me to think that lists _were_
> vectors, just not vectors of atomic mode. And one oft-illustrated method for
> creating a list is:  alist <- vector(mode="list", length=10). I am perhaps
> less confused than I was two years ago but my confusion about all the
> possible permutations of mode, typeof, expression, formula, and class and
> the extraction methods therefrom definitely persists. I think the authors of
> the documentation are of divided opinion or usage on this topic.

I probably should have said "atomic vectors" - it's easy to get
confused when you fail to be specific.  Data frames add even more
confusion:

> is.vector(as.vector(mtcars))
[1] FALSE

(That behaviour matches the documentation, but it's still confusing!)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list