R: [R] Indexing lists

Vito Muggeo vito.muggeo at giustizia.it
Thu Sep 16 14:21:53 CEST 2004


Hi,
Probably it should be useful to obtain two "results" which you can combine
according to what you need. Here a possible solution:

a<-b<-data.frame(matrix(runif(30),10,3))
d<-list(a,b) #your list
#extract the 1st column. The output is a nrow(a)-by-length(d) matrix
sapply(d,function(x)x[,1])

#extract the 1st row. The output is a ncol(a)-by-length(d) matrix
sapply(d,function(x)x[1,]) #a ncol(a)-by-length(d) matrix

Note if the dimensions of dataframes are different you will get lists.
Anyway, if you prefer lists rather than matrices use lapply()

best,
vito


----- Original Message -----
From: Perez Martin, Agustin <agustin.perez at umh.es>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, September 16, 2004 1:33 PM
Subject: [R] Indexing lists


> DeaR useRs:
>
> I have a list with 500 elements, in each other there are data.frames and I
> want to take the first row and the first column of each elements of my
list
> since the first to the 500-th.
>
> Thanks and excuse my bad English.
>
> ---
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list