Richard A. O'Keefe
2003-Oct-08 21:36 UTC
is.na(v)<-b (was: Re: [R] Beginner's query - segmentation fault)
Concerning x[i] <- NA vs is.na(x[i]) <- TRUE Brian Ripley wrote: I don't think it can ever `go wrong', but it can do things other than the user intends. If the user writes x[i] <- NA, the user has clearly indicated his intention that the i element(s) of x should become NA. There isn't any clearer way to say that. The only way it could ever do something "other than the user intends" is if the mode of x changes or the selected elements are set to something other than NA. The ?NA help page *hints* that this might be the case, but does not give an example. The question remains, *WHAT* can x[i]<-NA do that might be other than what the user intends? An example (especially one added to the ?NA help) would be very useful. The intention of is.na<- is clearer, I find this extremely puzzling. x[i] <- NA is an extremely clear and obvious way of saying "I want the i element(s) of x to become NA". is.na(x) <- ... is not only an indirect way of doing this, it is a way which is confusing and error-prone. Bear in mind that one way of implementing something is is.na() would be to associate a bit with each element of a vector; is.na() would test and "is.na<-"() would set that bit. It would be possible to have a language exactly like R -except- that x <- 1 is.na(x) <- TRUE x => NA is.na(x) <- FALSE x => 1 would work. The very existence of an "is.na<-" which accepts a logical vector containing FALSE as well as TRUE strongly suggests this. But it doesn't work like that. As I've pointed out, is.logical(m) && length(m) == length(x) && done{is.na(x) <- m} => identical(is.na(x), m) is the kind of behaviour that has been associated with well-behaved sinister function calls for several decades, and yet this is not a fact about R. and so perhaps user error is less likely? I see no reason to believe this; the bad behaviour of "is.na<-" surely makes user error *more* likely rather than *less* likely.
Seemingly Similar Threads
- is.na(v)<-b (was: Re: Beginner's query - segmentation fault)
- is.na(v)<-b (was: Re: Beginner's query - segmentation fault)
- is.na(v)<-b (was: Re: Beginner's query - segmentation fault)
- is.na(v)<-b (was: Re: Beginner's query - segmentation fault)
- is.na(v)<-b (was: Re: Beginner's query - segmentation fault)