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
Not sure if this is the best way ... but something similar to my question from yesterday that I could solve as follows. > tD <- read.csv("Book1.csv") > tD X0 X0.1 X1 X1.1 X X.1 1 13 5 NA NA NA 2 44 NA NA NA NA 3 7 -1 89 10 6 > x1 <- tD[1,1:3] > > x2 <- tD[2,1:2] > >