[R] [Q] a dummy variable used with sapply

GMail (KU) youngjin.lee.ku at gmail.com
Sat Aug 7 20:00:06 CEST 2010


Hello,

While learning how to manipulate data with R, I found one example that I could not understand. 

In the following example, the function definition of "maxcor" has an argument named "i" and I don't understand why. 
Could someone explain why the maxcor function definition needs to have this argument?

maxcor = function(i, n = 10, m = 5)
{ 
    mat = matrix(rnorm(n*m),n,m) 
    corr = cor(mat) 
    diag(corr) = NA 
    max(corr,na.rm=TRUE)
}

> maxcors = sapply(1:1000, maxcor, n = 100)

Thanks in advance.

Young-Jin Lee


More information about the R-help mailing list