[R] Preserving numeric columns

Felipe Carrillo
Sat, 19 Oct 2019 07:44:26 -0000

Consider the following dataset:? I need to replace NAs with "-" but I
lose my numeric formatting??fall.estimate <- structure(list(`Salmon` =
c("salmon River",?"Ant Creek", "big Creek",
"oso River", "linda Creek"), `baseline` = c(80874.384012,
361.1997, 5012.8311,?638.6912, 402.104433333333), `target` = c(160000,?720,
10000, 450, 800), `1992` = c(27618.4365, 0, 3587.61719,?NA, NA), `1993` =
c(100027.82328, NA, 5647.83116, NA, NA), `1994` = c(99414.57438,?NA,
12896.93753, NA, NA), `1995` = c(235027.00518, NA, 32059.63037,?NA, NA), `1996`
= c(143004.6423, NA, 17191.2152, NA, NA), `1997` = c(112796.88894,?NA,
27365.24435, NA, NA), `1998` = c(102858.8148, NA, 20539.17372,?NA, NA), `1999` =
c(94113.26562, NA, 21916.44213, NA, NA)), row.names = c(NA,?-5L), class =
c("tbl_df", "tbl", "data.frame"))
fall.estimatestr(fall.estimate)#convert to class dataframefall.estimate <-
as.data.frame(fall.estimate)
#Remove all decimalsfall.estimate[,-1] <-round(fall.estimate[,-1],0)#Replace
NA's' with dash '-'fall.estimate[is.na(fall.estimate)] <-
"-"
#Here all my columns get converted to character#Try to convert back to
numericfall.estimate <- mutate_all(fall.estimate, function(x)
as.numeric(as.character(x)))?fall.estimate#But I get these warnings aand my
dashes dissapearQuestion: How can I replace my NAs with dashes and keep all my
dataframecolumns as numeric??Warning messages:1: In FUN(newX[, i], ...) : NAs
introduced by coercion2: In FUN(newX[, i], ...) : NAs introduced by coercion3:
In FUN(newX[, i], ...) : NAs introduced by coercion4: In FUN(newX[, i], ...) :
NAs introduced by coercion5: In FUN(newX[, i], ...) : NAs introduced by
coercion6: In FUN(newX[, i], ...) : NAs introduced by coercion7: In FUN(newX[,
i], ...) : NAs introduced by coercion8: In FUN(newX[, i], ...) : NAs introduced
by coercion9: In FUN(newX[, i], ...) : NAs introduced by coercion
Thanks beforehand


	[[alternative HTML version deleted]]