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
7 messages · Göran Broström, Eric Berger, Jeff Newmiller +2 more
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
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 <goran.brostrom at umu.se> 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"
x
A "A" "B" NA What happens? G_ran
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
I don't find _either_ of these acceptable.
On the other hand,
x[ is.na( x ) ] <- 1
should have no effect on x.
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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Sent from my phone. Please excuse my brevity.
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
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 <goran.brostrom at umu.se> 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"
x
A "A" "B" NA What happens? G_ran
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
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 ) ] <- 1
should have no effect on x.
On December 16, 2022 10:28:52 AM PST, "G?ran Brostr?m" <goran.brostrom at umu.se> 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"
x
A "A" "B" NA What happens? G_ran
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
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. -Bill On Fri, Dec 16, 2022 at 10:29 AM G?ran Brostr?m <goran.brostrom at umu.se> 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"
x
A "A" "B" NA What happens? G_ran
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
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 at gmail.com> Datum: fredag, 16 december 2022 20:15 Till: G?ran Brostr?m <goran.brostrom at umu.se> Kopia: r-help at r-project.org <r-help at 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
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 at r-project.org<mailto:R-help at 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.