[R] programming advice

Fred JEAN frederic.jean at univ-brest.fr
Thu Jun 22 17:58:06 CEST 2006

Dear R users

I want to compute Kendall's Tau between two vectors x and y.
But x and y  may have zeros in the same position(s) and I wrote the
following function to be sure to drop out those "double zeros"

"cor.kendall" <- function(x,y) {
  nox <- c()
  noy <- c()
  for (i in 1:length(x)) if (x[i]!= 0 | y[i] != 0)
      nox[length(nox)+1]<- x[i]
  for (i in 1:length(y)) if (x[i]!= 0 | y[i] != 0)
      noy[length(noy)+1]<- y[i]
  res.kendall <- cor.test(nox,noy,method = "kendall",exact=F)

Do you know a more elegant way to achieve the same goal ?
(I'm sure you do : it's a newbie's program actually)


More information about the R-help mailing list