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

2022-12-17 Thread Göran Broström
Thanks to all. I was cofused and forgot that in is.na(x) <- value, value is an index vector. Clearly stated on the help page. So Bert's suggestion is the right one. Den 2022-12-16 kl. 19:44, skrev Jeff Newmiller: I don't find _either_ of these acceptable. On the other hand, x[ is.na( x

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

2022-12-16 Thread Göran Broström
pia: r-help@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]<

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

2022-12-16 Thread Bill Dunlap
I think that is.na(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(x)<-i. It is possible that some classes mess up this equivalence, but I think that would be considered a bug. -

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

2022-12-16 Thread Bert Gunter
To do what the OP wanted, one can use: x <- c('A', 'B') is.na(x) <- x=='A' ## rhs is a logical index vector ## yielding > x [1] NA "B" Cheers, Bert On Fri, Dec 16, 2022 at 10:43 AM Eric Berger wrote: > maybe this will make it clear > > x <- c(a=1, b=5) > is.na(x) <- "b" > > i.e. your second

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

2022-12-16 Thread Jeff Newmiller
I don't find _either_ of these acceptable. On the other hand, x[ is.na( x ) ] <- 1 should have no effect on x. On December 16, 2022 10:28:52 AM PST, "Göran Broström" wrote: >I'm confused: > >> x <- 1:2 >> is.na(x) <- 1 >> x >[1] NA 2 > >OK, but > >> x <- c("A", "B") >> is.na(x) <- "A" >>

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

2022-12-16 Thread Eric Berger
maybe this will make it clear x <- c(a=1, b=5) is.na(x) <- "b" i.e. your second case is dealing with a named vector HTH, Eric On Fri, Dec 16, 2022 at 8:29 PM Göran Broström wrote: > I'm confused: > > > x <- 1:2 > > is.na(x) <- 1 > > x > [1] NA 2 > > OK, but > > > x <- c("A", "B") > > is.na(

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

2022-12-16 Thread Göran Broström
I'm confused: > x <- 1:2 > is.na(x) <- 1 > x [1] NA 2 OK, but > x <- c("A", "B") > is.na(x) <- "A" > x A "A" "B" NA What happens? G_ran __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mai