Re: [R] na.rm problem

From: Ulrich Keller <uhkeller_at_web.de>
Date: Tue 01 Aug 2006 - 21:38:38 EST

Like the error message tells you, cor does not have an argument "na.rm". use="complete" already does what you want, namely casewise deletion of missing values.

However, this will not work with vectors of unequal length (how is R to determine which observations in x correspond to those in y?). What you could do is create a copy of y that has the same length as x but is "padded" with NAs (missing values) using something like:

y.NA<-c(rep(NA, length(x) - length(y)), y)

Then you can compute the correlation:

cor(x, y.NA, use="complete")

sonal@deepfoo.com wrote:
> hi,
>
> i am a new member.
>
> i am using R in finding correlation between two variables of unequal length.
>
> when i use
>
> cor(x,y,na.rm=T,use="complete")
>
> where x has observations from 1928 to 2006 & y has observations from 1950 to
> 2006. I used na.rm=T to use the "complete observations". So missing values
> should be handled by casewise deletion. But it gives me error
>
> Error in cov(close, close1, na.rm = T, use = "complete") :
> unused argument(s) (na.rm ...)
>
>
> Please help me with this as I am new to R.
>
> Thanks,
> Sonal
>
> ______________________________________________
> R-help@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
> and provide commented, minimal, self-contained, reproducible code.
>
>



R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Tue Aug 01 22:50:17 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 02 Aug 2006 - 00:17:36 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.