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
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 cor(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
sonal at 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 cor(close, close1, na.rm = T, use = "complete") : > unused argument(s) (na.rm ...) > > Please help me with this as I am new to R.See ?cor. It does not have an na.rm argument. Just use: cor(x, y, use = "complete") Uwe Ligges> Thanks, > Sonal > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code.
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 at 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 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 > and provide commented, minimal, self-contained, reproducible code. > >