Re: [R] List indexing question

2012-05-21 Thread arun
Hi David, Try > x[[2]][1] [1] 4 > A.K. - Original Message - From: David Perlman To: r-help@r-project.org Cc: Sent: Monday, May 21, 2012 8:07 PM Subject: [R] List indexing question Consider the following: > x<-list(c(1,2,3),c(4,5,6)) > x[1] [[1]] [1] 1 2 3 > x[

Re: [R] List indexing question

2012-05-21 Thread Michael Sumner
There is also the recursive extraction with "[[": x[[c(2, 1)]] [1] 4 >From ?Extract " ‘[[’ can be applied recursively to lists, so that if the single index ‘i’ is a vector of length ‘p’, ‘alist[[i]]’ is equivalent to ‘alist[[i1]]...[[ip]]’ providing all but the final indexing resu

Re: [R] List indexing question

2012-05-21 Thread R. Michael Weylandt
It's a little funny, you actually need x[[2]][1] What's going on is the following: lists can contain anything else in R, including more lists so subsetting them takes a hair more work. x[2] returns the sublist of x containing the second list element -- this is, however, not the same as x[[2]] wh

[R] List indexing question

2012-05-21 Thread David Perlman
Consider the following: > x<-list(c(1,2,3),c(4,5,6)) > x[1] [[1]] [1] 1 2 3 > x[2] [[1]] [1] 4 5 6 So far that all seems reasonable. But now there's a problem. I'm used to python, where I would say x[2][1] and get the value 4. But I can't figure out how to do that in R. > x[2][1] [[1]] [1]