[R] Matrix elements are vectors

Duncan Murdoch murdoch at stats.uwo.ca
Mon Apr 5 21:35:34 CEST 2010


On 05/04/2010 3:20 PM, Trafim Vanishek wrote:
> Dear all,
>
> My question how is it possible to define a matrix A with 10 rows 1 column,
> so that its elements are vectors of undefined length.
>
> I need to have a possibility later to add elements like A[1,1] <-
> c(A[1,1],3,4,5)
>
> Thanks a lot for the help!
You create the matrix from a list:

A <- matrix( as.list(1:10), 10, 1)

But now you need to be careful:  This won't work

A[1,1] <- c(A[1,1],3,4,5)

you need


A[[1,1]] <- c(A[[1,1]],3,4,5)

Duncan Murdoch



More information about the R-help mailing list