Diogo Alagador
2007-Oct-22 14:48 UTC
[R] median value dataframe coming from multiple dataframes
Hi all, I am not a skillful R programmer and has I am handling with large dataframes (about 30000 x 300) I am in need of an efficient function. I have 4 dataframes with the same dimension. I need to generate other dataframe with the some dimension than the others where in each position it has the median value of the 4 values in the same position coming from the 4 dataframes. Grateful by your support, Diogo André Alagador [[alternative HTML version deleted]]
Henrique Dallazuanna
2007-Oct-22 15:30 UTC
[R] median value dataframe coming from multiple dataframes
Perhaps:
[[1]]
x v
1 1 1.0565171
2 2 -0.8273003
3 3 1.0614944
4 4 2.6897433
5 5 0.7371014
6 6 -1.3192476
[[2]]
x v
1 1 1.7267265
2 2 -0.2470332
3 3 -0.1667343
4 4 -0.4970180
5 5 -1.0597913
6 6 0.3742491
[[3]]
x v
1 1 1.3846207
2 2 0.7995231
3 3 -0.6818515
4 4 0.4711960
5 5 1.9666241
6 6 -0.1185372
[[4]]
x v
1 1 -1.6236832
2 2 0.9617151
3 3 1.1262914
4 4 0.2224509
5 5 1.2749641
6 6 -0.2390259
df_out <- matrix(0, ncol=ncol(df1), nrow=nrow(df1))
for(i in 1:ncol(df1)){
df_out[,i] <- apply(do.call("rbind", lapply(list(df1, df2, df3,
df4), "[[",
i)), 2, median)
}
On 22/10/2007, Diogo Alagador <alagador@oniduo.pt>
wrote:>
> Hi all,
>
> I am not a skillful R programmer and has I am handling with large
> dataframes (about 30000 x 300) I am in need of an efficient function.
>
> I have 4 dataframes with the same dimension. I need to generate other
> dataframe with the some dimension than the others where in each position it
> has the median value of the 4 values in the same position coming from the 4
> dataframes.
>
> Grateful by your support,
>
> Diogo André Alagador
>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]
Diogo Alagador
2007-Oct-22 17:44 UTC
[R] median value dataframe coming from multiple dataframes
Hi Henrique,
Much thanks (obrigado!!!) for your quick answer,
I have built a function from you suggestions that took the following script:
teste=function(...){
df_out = matrix(0, ncol=ncol(..1), nrow=nrow(..1));
for(i in 1:ncol(..1)){
df_out[,i] = apply(do.call("rbind", lapply(list(...), "[[",
i)), 2, median);
return(df_out)
}
}
When I applied it to 4 matrices just gave:
x v
1 1 0
2 1 0
3 1 0
4 1 0
5 1 0
6 1 0
It seems there is a problem here.
Any re-suggestion?
All the best,
Diogo André Alagador
Portugal
From: Henrique Dallazuanna [mailto:wwwhsd@gmail.com]
Sent: segunda-feira, 22 de Outubro de 2007 17:31
For: Diogo Alagador
Cc: r-help@r-project.org
: Re: [R] median value dataframe coming from multiple dataframes
Perhaps:
[[1]]
x v
1 1 1.0565171
2 2 -0.8273003
3 3 1.0614944
4 4 2.6897433
5 5 0.7371014
6 6 -1.3192476
[[2]]
x v
1 1 1.7267265
2 2 -0.2470332
3 3 -0.1667343
4 4 -0.4970180
5 5 -1.0597913
6 6 0.3742491
[[3]]
x v
1 1 1.3846207
2 2 0.7995231
3 3 -0.6818515
4 4 0.4711960
5 5 1.9666241
6 6 -0.1185372
[[4]]
x v
1 1 -1.6236832
2 2 0.9617151
3 3 1.1262914
4 4 0.2224509
5 5 1.2749641
6 6 -0.2390259
df_out <- matrix(0, ncol=ncol(df1), nrow=nrow(df1))
for(i in 1:ncol(df1)){
df_out[,i] <- apply(do.call("rbind", lapply(list(df1, df2, df3,
df4), "[[", i)), 2, median)
}
On 22/10/2007, Diogo Alagador <alagador@oniduo.pt
<mailto:alagador@oniduo.pt> > wrote:
Hi all,
I am not a skillful R programmer and has I am handling with large dataframes
(about 30000 x 300) I am in need of an efficient function.
I have 4 dataframes with the same dimension. I need to generate other dataframe
with the some dimension than the others where in each position it has the median
value of the 4 values in the same position coming from the 4 dataframes.
Grateful by your support,
Diogo André Alagador
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org <mailto:R-help@r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
<http://www.r-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]
Diogo Alagador
2007-Oct-22 19:57 UTC
[R] median value dataframe coming from multiple dataframes
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@gmail.com]
Sent: segunda-feira, 22 de Outubro de 2007 21:03
for: Diogo Alagador
Cc: r-help@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)
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]