Vayder
Vayder

Reputation: 45

How do i replace values with numeric entry "0.0" and replace them with "1.0" in R?

      Date     V1
2015-01-11    0.0

Now there are many vaules like these in my data frame. So i want all of them to be replaced by 1. I think creating another dataframe with all 0 values and then replacing them with 1 and merging again using left join will not place them back to their specific dates. Please help!

Upvotes: 0

Views: 385

Answers (2)

Vayder
Vayder

Reputation: 45

I got the answer, Thanks!

df= df %>% mutate(V1 = replace(V1, V1 == '0', '1'))

Upvotes: 1

Mr.Rlover
Mr.Rlover

Reputation: 2623

Here's a base R solution

df[df==0] <- 1

Upvotes: 1

Related Questions