[R] apply fun to df returning a matrix

Mohamed Lajnef Mohamed.lajnef at inserm.fr
Fri Apr 30 12:59:25 CEST 2010


Hi Soeren

Apply or aggregate functions

best regards
M
Soeren.Vogel at eawag.ch a écrit :
> Hello, a data.frame, df, holds the numerics, x, y, and z. A function, 
> fun, should return some arbitrary statistics about the arguments, e.g. 
> the sum or anything else. What I want to do is to apply this function 
> to every pair of variables in df, and the return should be a matrix as 
> found with cov. How can I achieve that? Thanks, Sören
>
> df <- data.frame(x=1:10, y=11:20, z=21:30);
> fun <- function(x){
>   return(sum(x));
> }
> # and now???
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>


-- 


Mohamed Lajnef,IE 
INSERM U955 eq 15
Pôle de Psychiatrie
Hôpital CHENEVIER
40, rue Mesly
94010 CRETEIL Cedex FRANCE
Mohamed.lajnef at inserm.fr
tel : 01 49 81 31 31 (poste 18470)
Sec : 01 49 81 32 90
fax : 01 49 81 30 99 



More information about the R-help mailing list