Ken Spriggs
2008-Feb-27 21:34 UTC
[R] Error in cor.default(x1, x2) : missing observations in cov/cor
Hello, I'm trying to do cor(x1,x2) and I get the following error: Error in cor.default(x1, x2) : missing observations in cov/cor A few things: 1. I've used cor() many times and have never encountered this error. 2. length(x1) = length(x2) 3. is.numeric(x1) = is.numeric(x2) = TRUE 4. which(is.na(x1)) = which(is.na(x2)) = integer(0) {the same goes for is.nan()} 5. I also try cor(x1,x2, use = "all.obs") and get the same error. What can be going wrong? -- View this message in context: http://www.nabble.com/Error-in-cor.default%28x1%2C-x2%29-%3A-missing-observations-in-cov-cor-tp15723848p15723848.html Sent from the R help mailing list archive at Nabble.com.
Peter Dalgaard
2008-Feb-27 21:55 UTC
[R] Error in cor.default(x1, x2) : missing observations in cov/cor
Ken Spriggs wrote:> Hello, > > I'm trying to do cor(x1,x2) and I get the following error: > Error in cor.default(x1, x2) : missing observations in cov/cor > > A few things: > 1. I've used cor() many times and have never encountered this error. > 2. length(x1) = length(x2) > 3. is.numeric(x1) = is.numeric(x2) = TRUE > 4. which(is.na(x1)) = which(is.na(x2)) = integer(0) {the same goes for > is.nan()} > 5. I also try cor(x1,x2, use = "all.obs") and get the same error. > > What can be going wrong? > > >Er, this is strange. As far as I can see, cor is not normally generic, and > getAnywhere("cor.default") no object named ?cor.default? was found so something is not normal. What do you get from a traceback() after the error, which is your cor.default, and what is the class of x1 and x2? Do you perchance have some special packages loaded? -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Erik Iverson
2008-Feb-27 21:58 UTC
[R] Error in cor.default(x1, x2) : missing observations in cov/cor
What happens when you type "cor" at the R prompt? Perhaps your calling of the cor function is not calling the cor function in the stats package? Ken Spriggs wrote:> Hello, > > I'm trying to do cor(x1,x2) and I get the following error: > Error in cor.default(x1, x2) : missing observations in cov/cor > > A few things: > 1. I've used cor() many times and have never encountered this error. > 2. length(x1) = length(x2) > 3. is.numeric(x1) = is.numeric(x2) = TRUE > 4. which(is.na(x1)) = which(is.na(x2)) = integer(0) {the same goes for > is.nan()} > 5. I also try cor(x1,x2, use = "all.obs") and get the same error. > > What can be going wrong? > >
Daniel Malter
2008-Feb-28 00:40 UTC
[R] Error in cor.default(x1, x2) : missing observations in cov/cor
Does the code below solve your problem? If you have NAs in the same rows, you have to use "c" or "p" as use= parameters. Otherwise you get the error you described. a=c(1,2,3,4,NA,6) b=c(2,4,3,5,NA,7) which(is.na(a))==which(is.na(b)) cor(a,b) ####Error cor(a,b,use="all.obs") ####Error cor(a,b,use="complete.obs") #### Does it. AND cor(a,b,use="pairwise.complete.obs") #### Does it too. ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von Ken Spriggs Gesendet: Wednesday, February 27, 2008 4:34 PM An: r-help at r-project.org Betreff: [R] Error in cor.default(x1, x2) : missing observations in cov/cor Hello, I'm trying to do cor(x1,x2) and I get the following error: Error in cor.default(x1, x2) : missing observations in cov/cor A few things: 1. I've used cor() many times and have never encountered this error. 2. length(x1) = length(x2) 3. is.numeric(x1) = is.numeric(x2) = TRUE 4. which(is.na(x1)) = which(is.na(x2)) = integer(0) {the same goes for is.nan()} 5. I also try cor(x1,x2, use = "all.obs") and get the same error. What can be going wrong? -- View this message in context: http://www.nabble.com/Error-in-cor.default%28x1%2C-x2%29-%3A-missing-observa tions-in-cov-cor-tp15723848p15723848.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at 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.
Daniel Malter
2008-Feb-28 00:49 UTC
[R] Error in cor.default(x1, x2) : missing observations in cov/cor
Sorry, I overlooked the = integer(0) result to which(is.na(x1))==which(is.na(x2)). So that's not it. Cheers. ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: Daniel Malter [mailto:daniel at umd.edu] Gesendet: Wednesday, February 27, 2008 7:41 PM An: 'Ken Spriggs'; 'r-help at r-project.org' Betreff: AW: [R] Error in cor.default(x1, x2) : missing observations in cov/cor Does the code below solve your problem? If you have NAs in the same rows, you have to use "c" or "p" as use= parameters. Otherwise you get the error you described. a=c(1,2,3,4,NA,6) b=c(2,4,3,5,NA,7) which(is.na(a))==which(is.na(b)) cor(a,b) ####Error cor(a,b,use="all.obs") ####Error cor(a,b,use="complete.obs") #### Does it. AND cor(a,b,use="pairwise.complete.obs") #### Does it too. ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von Ken Spriggs Gesendet: Wednesday, February 27, 2008 4:34 PM An: r-help at r-project.org Betreff: [R] Error in cor.default(x1, x2) : missing observations in cov/cor Hello, I'm trying to do cor(x1,x2) and I get the following error: Error in cor.default(x1, x2) : missing observations in cov/cor A few things: 1. I've used cor() many times and have never encountered this error. 2. length(x1) = length(x2) 3. is.numeric(x1) = is.numeric(x2) = TRUE 4. which(is.na(x1)) = which(is.na(x2)) = integer(0) {the same goes for is.nan()} 5. I also try cor(x1,x2, use = "all.obs") and get the same error. What can be going wrong? -- View this message in context: http://www.nabble.com/Error-in-cor.default%28x1%2C-x2%29-%3A-missing-observa tions-in-cov-cor-tp15723848p15723848.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at 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.