[R] is.na()<- on a character vector

Göran Broström gor@n@bro@trom @end|ng |rom umu@@e
Fri Dec 16 20:38:57 CET 2022


Yes, I was confused: In is.na(x) <-value, value is supposed to be an index vector, clearly stated on the help page. So Bert�s suggestion is the way to go.

Thanks to all, G�ran

-----Ursprungligt meddelande-----
Fr�n: Bill Dunlap <williamwdunlap using gmail.com>
Datum: fredag, 16 december 2022 20:15
Till: G�ran Brostr�m <goran.brostrom using umu.se>
Kopia: r-help using r-project.org <r-help using r-project.org>
�mne: Re: [R] is.na()<- on a character vector
I think that is.na <http://is.na/><http://is.na/%3e>(x) <- i
generally does the same to x as does
x[i] <- NA


I say 'generally' because some classes (e.g., numeric_version) do not allow x[i]<-NA but do allow is.na <http://is.na/><http://is.na/%3e>(x)<-i. It is possible that some classes mess up this equivalence, but I think that would be considered a bug.


-Bill


On Fri, Dec 16, 2022 at 10:29 AM G�ran Brostr�m <goran.brostrom using umu.se<mailto:goran.brostrom using umu.se> <mailto:goran.brostrom using umu.se<mailto:goran.brostrom using umu.se>>> wrote:

I'm confused:

> x <- 1:2
> is.na <http://is.na/><http://is.na/%3e>(x) <- 1
> x
[1] NA 2

OK, but

> x <- c("A", "B")
> is.na <http://is.na/><http://is.na/%3e>(x) <- "A"
> x
A
"A" "B" NA

What happens?

G_ran

______________________________________________
R-help using r-project.org<mailto:R-help using r-project.org> <_blank> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help><https://stat.ethz.ch/mailman/listinfo/r-help%3e>
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.r-project.org/posting-guide.html><http://www.r-project.org/posting-guide.html%3e>
and provide commented, minimal, self-contained, reproducible code.



	[[alternative HTML version deleted]]



More information about the R-help mailing list