Search
 
SCRIPT & CODE EXAMPLE
 

R

dplyr replace na

df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b"))

df %>% dplyr::mutate(x = replace_na(x, 0))
#> # A tibble: 3 x 2
#>       x y    
#>   <dbl> <chr>
#> 1     1 a    
#> 2     2 NA   
#> 3     0 b

# To replace NA in two columns
df %>% replace_na(list(x = 0, y = "unknown"))
#> # A tibble: 3 x 2
#>       x y      
#>   <dbl> <chr>  
#> 1     1 a      
#> 2     2 unknown
#> 3     0 b      
Comment

PREVIOUS NEXT
Code Example
R :: r delete all variables 
R :: r find elements in common between vectors 
R :: how to fill na values in r 
R :: how to add random numbers randomly in a dataframe in r 
R :: R sort matrix 
R :: size of ticks labels in r ggplot 
R :: r list append 
R :: composite score in r 
R :: multiple intersect r 
R :: sort R 
R :: r change row names of a dataframe 
R :: diff days R lubridate 
R :: custom function in r 
R :: how to change the numbering of rows in r 
R :: how to read in a text file in r 
R :: r make directory 
R :: r find nas in dataframe 
R :: table() in r 
R :: find nas in dataframe r 
R :: if condition is met skip to next iteration in a for loop in r 
R :: 3d scatter plot in r 
R :: logical vector passed in R 
R :: eleminating a char in of a list in r 
R :: extract residual standard error from lm in r 
R :: créer un dataframe dans r 
R :: dplyr left join only certain columns 
Rust :: hello world rust 
Rust :: for loops in rust 
Rust :: actix web 
Rust :: rust variables in println 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =