You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You want to specify certain columns that contain NA and replace it with another value such as 0.
For example, smiths, a dataset contained in tidyr, has a couple of NA values in age and weight columns.
smiths
# A tibble: 2 x 5
subject time age weight height
<chr> <dbl> <dbl> <dbl> <dbl>
1 John Smith 1 33 90 1.87
2 Mary Smith 1 NA NA 1.54
Solution {-}
smiths %>%
replace_na(list(age = 0, weight = 0))
# A tibble: 2 x 5
subject time age weight height
<chr> <dbl> <dbl> <dbl> <dbl>
1 John Smith 1 33 90 1.87
2 Mary Smith 1 0 0 1.54
Discussion {-}
If data is a dataframe or tibble, you need to create a list inside replace_na with the name of columns on the left hand side and value to replace NA with on the right hand side.
If data is a vector, you insert a single value used for replacement.
The text was updated successfully, but these errors were encountered:
You want to specify certain columns that contain
NA
and replace it with another value such as0
.For example,
smiths
, a dataset contained intidyr
, has a couple ofNA
values inage
andweight
columns.Solution {-}
Discussion {-}
If
data
is a dataframe or tibble, you need to create a list insidereplace_na
with the name of columns on the left hand side and value to replaceNA
with on the right hand side.If
data
is a vector, you insert a single value used for replacement.The text was updated successfully, but these errors were encountered: