[R] median value dataframe coming from multiple dataframes
Alberto Murta
amurta at ipimar.pt
Tue Oct 23 11:48:38 CEST 2007
See if this solves your problem:
dataframe1 <- as.data.frame(matrix(runif(30000*300), 30000, 300))
dataframe2 <- as.data.frame(matrix(runif(30000*300), 30000, 300))
dataframe3 <- as.data.frame(matrix(runif(30000*300), 30000, 300))
dataframe4 <- as.data.frame(matrix(runif(30000*300), 30000, 300))
dataframe.list <- list(dataframe1,dataframe2,dataframe3,dataframe4)
array.temp <- array(NA, c(30000,300,4))
for(i in 1:length(dataframe.list)){
array.temp[,,i] <- data.matrix(dataframe.list[[i]])
}
final.dataframe <- as.data.frame(apply(array.temp, c(1,2), median))
On Monday 22 October 2007 8:57 pm, Diogo Alagador wrote:
> Sorry Henrique
>
> But I'm affraid now the result was
>
>
> x y
> 1 1 2
> 2 1 2
> 3 1 2
> 4 1 2
> 5 1 2
> 6 1 2
>
>
> I think we are very close to the solution. But it isn't this one!!!
>
> Where should I look for?
>
>
> Sorry for the inconvenience,
>
> Diogo André Alagador
> Portugal
>
>
>
>
> from: Henrique Dallazuanna [mailto:wwwhsd at gmail.com]
> Sent: segunda-feira, 22 de Outubro de 2007 21:03
> for: Diogo Alagador
> Cc: r-help at r-project.org
> Re: [R] median value dataframe coming from multiple dataframes
>
>
>
> Hi Diogo,
>
> teste <- function(x){
> if(!is.list(x))stop("A list is needed")
> df_out <- matrix(0, ncol=ncol(x[[1]]), nrow=nrow(x[[1]]))
> for(i in 1:ncol(x[[1]])){
> df_out[,i] <- apply( do.call("rbind", lapply(x, "[[", i)), 2,
> median) }
> return(df_out)
> }
>
> x <- list(df1, df2, df3, df4)
>
> teste(x)
--
Alberto G. Murta
IPIMAR - National Institute of Fisheries and Marine Research
Avenida de Brasilia s/n; 1449-006 - Lisboa; Portugal
Tel: +351 213027000; Fax: +351 21 3015948; email: amurta at ipimar.pt
More information about the R-help
mailing list