[R] programming advice

ronggui ronggui.huang at gmail.com
Thu Jun 22 18:13:19 CEST 2006


Will the following code work for you?
> index<-!(x==0 & y==0)
> x<-x[index]
> y<-y[index]


2006/6/22, Fred JEAN <frederic.jean at univ-brest.fr>:
> 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)
>   return(list(x=nox,y=noy,res.kendall,length(nox)))
> }
>
> Do you know a more elegant way to achieve the same goal ?
> (I'm sure you do : it's a newbie's program actually)
>
> --
> Fred
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>


-- 
»ÆÈÙ¹ó
Department of Sociology
Fudan University



More information about the R-help mailing list