[R] apply fun to df returning a matrix

Soeren.Vogel at eawag.ch Soeren.Vogel at eawag.ch
Fri Apr 30 13:55:01 CEST 2010


Hi Mohamed, thanks for your answer. Anyway, the "how to" is exactly my  
problem, since ...

fun2 <- function(x){
    
please_use_aggregate_and_apply_in_some_way_and_return_the_output_of_my_example_as_requested 
(fun(x));
}
fun2(df);

... unfortunately returns an error ;-). Could you please give a simple  
example? Thanks, Sören

On 30.04.2010, at 12:59, Mohamed Lajnef wrote:

> 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???



More information about the R-help mailing list