Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have variable a in a dataset b
NA NA NA 53 53 NA
I want the output as
1 1 1 53 53 1
I tried
b$a1[i1] <- ifelse(b$a[i1]=="NA", 1,b$a[i1])
But it is not getting replace. Format of a is list
is.na()
str(b)
The answer you are looking for is
b$a[is.na(b$a)] <- 1
Add a comment
We can use replace
replace
with(b, replace(a, is.na(a), 1))
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
is.na()function for checking whether the value is NA or notstr(b)?