0
I have a DF
that has some NA
, as I will use it to assemble a table, I needed to exchange the NA
by " ", to only show the empty space in the table. I am using a mutate_if
to leave the numbers to only two decimal places and exchange .
for ,
.
I tried using the following code, with mutate
and replace_na
, but it didn’t work, the NA
continue to appear.
library(tidyverse)
df %>%
mutate_if(is.numeric, format, scientific = FALSE, big.mark = ".", decimal.mark = ",", digits = 2) %>%
mutate_all(~ replace_na(., NA))
Man dput
:
df <- structure(list(a = c("Brasil", "Alimentação no domicílio",
"Arroz", "Feijão-carioca (rajado)", "Farinha de trigo"),
b = c(NA, 0.02, 2.71, 9.82, 3.35), c = c(NA, 0.38, 3.69, 10.96, 3.62),
d = c(NA, 0.87, 4.13, 7.28, 3.14), e = c(NA, 1.11, 4.02, 10.09, 3.24),
f = c(NA, 1.13, 4.27, 9.23, 3.43), g = c(NA, NA, 0.15367429760666, 0.0882935186561618, 0.0116253902185224)),
row.names = c(NA, 5L), class = "data.frame")
That to you helping?
– neves