Skip to content

Applying a function to all combinations of factors

2 messages · Marc Belisle, Jean Eid

#
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