Re: [R] arrays of arrays

2010-11-10 Thread Duncan Murdoch
On 10/11/2010 12:12 AM, Michael Bedward wrote: Hello Sachin, You have a "ragged array" and you can easily store this as a list of vectors... x<- list(c(0,0,1,1), c(1,3,5), 4, c(7, -1, 8, 9, 10, 6)) The only gotcha with this is that you will then need to use double brackets for the first index

Re: [R] arrays of arrays

2010-11-10 Thread Claudia Beleites
Hi Sachin, I guess there are several different possibilities that are more or less handy depending on your data: - lists were mentioned already, and I think they are the most "natural" representation of ragged arrays. Also very flexible, e.g. you can introduce more dimensions. But they can g

Re: [R] arrays of arrays

2010-11-09 Thread Michael Bedward
Hi Sachin, That's OK - you don't need to know the dimensions up front and you can add new vectors, or elements to an existing vector, as required. # empty list to start with X <- list() # we get a vector v1 <- c(1, 2, 3, 4, 5) # add it to the ragged array X <- c(X, list(v1)) # get another coup

Re: [R] arrays of arrays

2010-11-09 Thread sachinthaka . abeywardana
Hi Michael, Thanks for that. Its a starting point I guess. But what if I didn't know the length of the outer vector is? (i.e. all dimensions are variable). Or for that matter I don't actually know what the initial dimensions are going to be. All of it is created within a for loop. I was hoping fo

Re: [R] arrays of arrays

2010-11-09 Thread Michael Bedward
Hello Sachin, You have a "ragged array" and you can easily store this as a list of vectors... x <- list(c(0,0,1,1), c(1,3,5), 4, c(7, -1, 8, 9, 10, 6)) The only gotcha with this is that you will then need to use double brackets for the first index when retrieving values (single brackets will ret

Re: [R] arrays of arrays

2010-11-09 Thread sachinthaka . abeywardana
Hi Erik, Thanks for replying. Only problem with that is that each row has 5 elements (or 5 columns). I want varying number of columns as shown in my example. x<- 0 0 1 1 1 3 5 4

Re: [R] arrays of arrays

2010-11-09 Thread Erik Iverson
This type of object has the "matrix" class in R. So just use ?matrix to create it. matrix(1:25, ncol = 5) for example. On 11/09/2010 08:55 PM, sachinthaka.abeyward...@allianz.com.au wrote: Hi All, I want to have an array/ matrix that looks this x<- 0 0 1 1 1

Re: [R] arrays of arrays

2010-11-09 Thread Santosh Srinivas
X0 X0.1 X1 135 [[2]] X0 X0.1 44 [[3]] X0 X0.1 X1 X1.1X X.1 7 -189 106 > HTH, S -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of sachinthaka.abeyward...@allianz.com.au Sent:

[R] arrays of arrays

2010-11-09 Thread sachinthaka . abeywardana
Hi All, I want to have an array/ matrix that looks this x<- 0 0 1 1 1 3 5 4 4 7 -1 8 9 10 6 I hope this makes sense. So basically if I want x[1,3] it will access 0 and similarly x[4,2], -1. Thanks in ad