Complete.cases for MAC users


#1

Hi,

I just learnt the other day “complete.cases” function. The following code is giving me this error message:

Error in complete.cases(V3, V4) : not all arguments have the same length

which’s legit. Anyways, same exact code is being executed on R for windows, and giving me an output without error message.

V3<-c(1,2,3,4,5,6,7,NA,19,NA,98,NA,NA)
V4<-c("A",NA,"B",NA,"C",NA,"D",NA,"E","F","G",NA)
E<- complete.cases(V3,V4)
E
V3[E]
V4[E]

Can someone explain this to me? Thank you


#2

Could you please turn this into a reprex? It’s always helpful, but it’s especially relevant w/ what you’ve got above as the quotation marks have been automatically turned into &ldquo; and &rdquo; (“” vs "").

Here’s a nice writeup on how and why:


#3
V3<-c(1,2,3,4,5,6,7,NA,19,NA,98,NA,NA)
V4<-c("A",NA,"B",NA,"C",NA,"D",NA,"E","F","G",NA)
E<- complete.cases(V3,V4)
E
V3[E]
V4[E]

Thank you Mara!


#4

V3 and V4 are different lengths (13 and 12), so E results in an error.


#5

Thank you. I do understand that. Just try the same exact code on R for windows. Can you pls read my question again? Thanks


#6

There is nothing OS dependent in complete.cases function.

Most likely, you’ve missed something when you’ve copied your example.


#7

I’m pretty sure this has nothing to do with Windows/Mac. I’m getting the error on Windows with R3.4.1. You could post which versions of R you are running. Somebody with more knowledge than me could state whether the behaviour of complete.cases changed between different versions of R.


#8

I’ve got the same error with your code when run in macOS or Windows 10.

You have cleanly formatted code in your post which helps, but a reprex actually runs the code so we can see the errors you are seeing. Here is your code in the form of a reprex.

V3<-c(1,2,3,4,5,6,7,NA,19,NA,98,NA,NA)
V4<-c("A",NA,"B",NA,"C",NA,"D",NA,"E","F","G",NA)
E<- complete.cases(V3,V4)
#> Error in complete.cases(V3, V4): not all arguments have the same length
E
#> Error in eval(expr, envir, enclos): object 'E' not found
V3[E]
#> Error in eval(expr, envir, enclos): object 'E' not found
V4[E]
#> Error in eval(expr, envir, enclos): object 'E' not found

Created on 2018-02-23 by the reprex package (v0.2.0).