<html>
<tt>I'm trying to convert over some S-plus code to R, and am having
problems where it uses a matrix of lists.<br><br>
Here's some code that works as expected in S-plus:<br><br>
> x <- vector("list",6)<br>
> dim(x) <- c(2,3)<br>
> x[1,2] <- list(letters[10:11])<br>
> x<br>
[,1]
[,2] [,3] <br>
[1,] NULL, 0 character, 2 NULL, 0<br>
[2,] NULL, 0 NULL, 0 NULL, 0<br>
> x[1,2]<br>
[[1]]:<br>
[1] "j" "k"<br><br>
> x[3]<br>
[[1]]:<br>
[1] "j" "k"<br><br>
> x[[3]]<br>
[1] "j" "k"<br>
> <br><br>
The same commands in R do not produce the desired results (the assignment
of element 1,2 does not work, I can assign in a different way, but then
different types of indexing produce different results):<br>
> x <- vector("list",6)<br>
> dim(x) <- c(2,3)<br>
> x[1,2] <- list(letters[10:11]) # Can't
assign using array indexing<br>
Error: incompatible types in subset assignment<br>
> x[[3]] <-
letters[10:11]
# I can assign to the desired element<br>
> x<br>
[,1]
[,2]
[,3] # and it seems to produce the
matrix I want<br>
[1,] "NULL" "Character,2" "NULL"<br>
[2,] "NULL"
"NULL"
"NULL"<br>
>
x[1,2]
# but I get a different element by array indexing!<br>
[[1]]<br>
NULL<br><br>
>
x[[3]]
# the element is there for list or vector indexing!<br>
[1] "j" "k"<br>
> x[3]<br>
[[1]]<br>
[1] "j" "k"<br><br>
> <br><br>
My original way of creating the matrix of NULL's does not work in R
either:<br>
> matrix(vector("list", 6), nrow=2)<br>
Error in matrix(vector("list", 6), nrow = 2) : <br>
Unimplemented feature in
copyVector<br>
><br><br>
Is there anything I can do to make a matrix of lists work in R?<br><br>
thanks,<br><br>
Tony Plate<br>
</html>