Skip to content
Prev 59310 / 398502 Next

how to rewrite this without a loop ?

Stijn Lievens wrote:
Using the lapply function in the e-mail of James, I came up with the 
following.

<code>
  sum (as.numeric( lapply( split(perf.data, perf.data$dataset), 
function(x) cor(x[3],x[7],method="kendall") ) ))
</code>

So, first I split the dataframe into a list of dataframes using split,
and using lapply I get a list of correlations, which I convert to
numeric and finally sum up.

I definitely avoided the for-loop in this way, although I am not sure 
whether this is more efficient or not.

Cheers,

Stijn.