[R] Applying a function to all combinations of factors

2005-03-02 Thread Marc Belisle
Is there a way to apply a function, say cor(), to each combination of some number of variables, and this, without using loops? For example, I have day, hour, var1 and var2. How could I compute cor(var1,var2) for each day*hour combination and obtain a matrix with day, hour and the cor value for

Re: [R] Applying a function to all combinations of factors

2005-03-02 Thread jeaneid
you could use something like by(data, list(data1$day, data1$hour), function(x) cor(x[,var1], x[, var2])) This will return a list and then you can unlist and turn to matrix HTH Is there a way to apply a function, say cor(), to each combination of some number of variables, and this, without