Skip to content
Prev 321412 / 398500 Next

means in tables

Hi,

?YOu can load all the datasets directly from the directory in a list.



set.seed(25)
?lst1<-lapply(1:100,function(i) as.data.frame(matrix(sample(1:40,25,replace=TRUE),ncol=5)))
?length(lst1)
#[1] 100
library(abind)

apply(abind(lst1,along=3),c(1,2),mean)
#??????? V1??? V2??? V3??? V4??? V5
#[1,] 20.37 21.95 19.51 22.77 22.00
#[2,] 20.43 17.94 18.81 20.02 23.86
#[3,] 23.00 18.64 21.15 21.61 22.12
#[4,] 20.10 20.89 22.35 19.62 20.72
#[5,] 19.36 20.97 19.36 21.02 20.48

? mean(unlist(lapply(lst1,function(x) x[1,1])))
#[1] 20.37
mean(unlist(lapply(lst1,function(x) x[4,5])))
#[1] 20.72
?mean(unlist(lapply(lst1,function(x) x[5,2])))
#[1] 20.97


A.K.

----- Original Message -----
From: Silvano Cesar da Costa <silvano at uel.br>
To: arun <smartpink111 at yahoo.com>
Cc: 
Sent: Wednesday, April 10, 2013 6:02 PM
Subject: Re: [R] means in tables

Hi Arun,

I thought with an example with two tables I could generalize to the 100
tables that have. It did not work.

Actually have 100 tables in the format mentioned. I need to calculate the
average of the elements that are in the same position in the 100 tables.
---------------------------------------------
Silvano Cesar da Costa

Universidade Estadual de Londrina
Centro de Ci?ncias Exatas
Departamento de Estat?stica

Fone: (43) 3371-4346
---------------------------------------------