[R] List subsetting

Dieter Menne dieter.menne at menne-biomed.de
Thu Jun 25 09:18:04 CEST 2009




Ivo Shterev wrote:
> 
> 
> I have a question about list indexing. Lets say we have a list of 3 lists,
> each containing 3 different type elements:
> 
> 

(Details of your nice example code removed)


a=replicate(3, list(list(c(1,1,1), diag(3), c(2,2,2)))) 
str(a) # I prefer this to print(a) because it shows the structure better

# in steps
b = lapply(a,function(x){
    # print(str(a)) # put this here to know what you are doing
    x[2:3]
  }
)
#... mmm, not yet what  you wanted. Another try
b[1:2]

# I leave it as a easy exercise to jam this into a one-liner

---
Dieter

-- 
View this message in context: http://www.nabble.com/List-subsetting-tp24194764p24198222.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list