Error in converting Na values into 0 for raster.

Hi I have an error in Rstudio when I want to replace the NA values into 0.

"Error in value[j, ] : incorrect number of dimensions
In addition: Warning message:
In isFALSE(simplify) :
closing unused connection 3 (/var/folders/ym/g7mjd6cn7k3fbm0sks8qp8fr0000gn/T//RtmpuX2BcT/raster///r_tmp_2020-03-29_183744_11491_95243.gri)"

Hers's the function
rs1920[is.na(rs1920)] <- 0 #after run that I have that error. No idea...

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.

From the tidyr package documentation, here's one way to drop NAs

suppressPackageStartupMessages(library(dplyr)) 
suppressPackageStartupMessages(library(tidyr)) 
df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b"))
df %>% drop_na()
#> # A tibble: 1 x 2
#>       x y    
#>   <dbl> <chr>
#> 1     1 a
df %>% drop_na(x)
#> # A tibble: 2 x 2
#>       x y    
#>   <dbl> <chr>
#> 1     1 a    
#> 2     2 <NA>

Created on 2020-03-29 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.