[R] Null values In R.

0 views
Skip to first unread message

paul murima

unread,
Dec 2, 2008, 11:33:14 PM12/2/08
to r-h...@r-project.org, r-h...@stat.math.ethz.ch
Hi everyone.

I am having problems with NULL values. I understand in R one can
command the program to skip null values.
Can some one help me on the command line for that.
Do i enter is as part of the string in:
a<- read.table("filename.csv", header = T, row.names=1, sep=",");

My problem is largely when i attempt to use correlation for my data...
xcc <- cor(a);

The error i get is as follows

Error in cor(a) : missing observations in cov/cor
In addition: Warning message:
In cor(a) : NAs introduced by coercion


Regards

Paul Murima

______________________________________________
R-h...@r-project.org 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.

paul murima

unread,
Dec 2, 2008, 11:33:14 PM12/2/08
to r-h...@r-project.org, r-h...@stat.math.ethz.ch

Daniel Malter

unread,
Dec 2, 2008, 11:54:07 PM12/2/08
to paul murima, r-h...@r-project.org, r-h...@stat.math.ethz.ch
Hi, for your cor() command you will want to specify the "use" argument as
either "complete.obs" or as "pairwise.complete.obs". The difference between
the two is that the former only uses those observations for which ALL
information in "a" is available, whereas the latter uses information that is
available for all pairwise comparisons between variables in "a". For the
example below, use="c" would exclude observations 6 and 5, whereas use="p"
would exclude observations 6 and 5 for correlations between x and y, and x
and z, but it would only exclude observation 5 for the correlation between y
and z

x=c(1,2,3,4,5,NA)
y=c(2,3,3.5,4.75,NA,7)
z=c(5,8,7,6,NA,11)

a=data.frame(x,y,z)

cor(a)
cor(a,use="c")
cor(a,use="p")

Cheers,
Daniel


-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-...@r-project.org [mailto:r-help-...@r-project.org] Im
Auftrag von paul murima
Gesendet: Tuesday, December 02, 2008 11:33 PM
An: r-h...@r-project.org
Cc: r-h...@stat.math.ethz.ch
Betreff: [R] Null values In R.

Dieter Menne

unread,
Dec 3, 2008, 1:50:02 AM12/3/08
to r-h...@r-project.org


paul murima wrote:
>
>
> My problem is largely when i attempt to use correlation for my data...
> xcc <- cor(a);
>
> The error i get is as follows
>
> Error in cor(a) : missing observations in cov/cor
>

As Daniel suggested, it is always best to use the function's parameter to
handle NULLs. In other cases, it could help to do

a <- na.omit(a)

but be careful: this may throw away to many rows when you have more than 2
columns.

Dieter


--
View this message in context: http://www.nabble.com/Null-values-In-R.-tp20806622p20807696.html
Sent from the R help mailing list archive at Nabble.com.

Reply all
Reply to author
Forward
0 new messages