On 12-07-01 12:01 PM, mlell08 wrote:

After all, it seems a bit unlogical to me, because
1) c(a=2, b=3)$a works as expected

I'm curious about this: I get an error. I expected an error, so it worked as expected for me, but I think from the context that I deleted that you didn't expect one. Did you really not get one?


2) I've created a matrix containing lists and not atomic vectors by
    a<- array(list(NULL),dim=c(2,2))
    however, my added element seems to be converted to an atomic vector
    - without need because

3) I avoided vectorization (thanks for the link to R inferno! Very apt
    comparison;-)) by using the [[ operator for assignment
    (which seemed to work because else more than one matrix element
    would have been filled) so there should be no need for dropping names
    (which actually doesn't happen, because a[[1,1]]["a"] works

but if the operator [[<- works like this, there is no point in argueing?

So - what works:

a<- array(list(NULL),dim=c(2,2))
a[[1,1]]<- c(a=2,b=3)
a[[1,1]]
## a b
## 2 3

a[[1,1]]$a
## Fehler in a[[1, 1]]$a : $ operator is invalid for atomic vectors

This is the error I get in 1).


#Synonym??
a[[1,1]][["a",exact=FALSE]]
## 2

That's not a synonym.

Duncan Murdoch


a[[1,1]]["a"]
## a
## 2

class(a[[1,1]])<- "list"
a[[1,1]]$a
## 2

Regards, Moritz


______________________________________________
R-help@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.

Reply via email to