Simon Fear
2003-Oct-08 10:08 UTC
is.na(v)<-b (was: Re: [R] Beginner's query - segmentation fault)
Note this behaviour:> a<-"a" > a<-NA > mode(a)[1] "logical"> a<-"a" > is.na(a) <- T > mode(a)[1] "character" However after either way of assigning NA to a, is.na(a) is true, and it prints as NA, so I can't see it's ever likely to matter. [Why do I say these things? Expect usual flood of examples where it does matter.] Also if a is a character vector, a[2] <- NA coerces the NA to as.character(NA); again, just as one would hope/expect. I have to echo Richard O'K's remark: if <- NA can ever go wrong, is that not a bug rather than a feature? Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
Prof Brian Ripley
2003-Oct-08 10:49 UTC
is.na(v)<-b (was: Re: [R] Beginner's query - segmentation fault)
On Wed, 8 Oct 2003, Simon Fear wrote:> Note this behaviour: > > > a<-"a" > > a<-NA > > mode(a) > [1] "logical" > > a<-"a" > > is.na(a) <- T > > mode(a) > [1] "character" > > However after either way of assigning NA to a, is.na(a) is true, > and it prints as NA, so I can't see it's ever likely to matter. [Why > do I say these things? Expect usual flood of examples where it > does matter.] > > Also if a is a character vector, a[2] <- NA coerces the NA to > as.character(NA); again, just as one would hope/expect. > > I have to echo Richard O'K's remark: if <- NA can ever go wrong, > is that not a bug rather than a feature?I don't think it can ever `go wrong', but it can do things other than the user intends. The intention of is.na<- is clearer, and so perhaps user error is less likely? That is the thinking behind the function, anyway. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Reasonably Related 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)
- Numbers that look equal, should be equal, but if() doesn'tsee as equal (repost with code included)
- I've forgotten, why is box("") the default?