I followed the dplyr
-solution here:
converting multiple columns from character to numeric format in r to convert multiple character columns to numeric.
The code
is_all_numeric <- function(x)
{
!any(is.na(suppressWarnings(as.numeric(na.omit(x))))) & is.character(x)
}
df %>%
mutate_if(is_all_numeric,as.numeric) #%>%
str()
works perfectly. However, if I try to assign it to the df
(i.e. make changes to column type permanent) using
df <- df %>%
mutate_if(is_all_numeric,as.numeric) #%>%
str()
df
becomes Null
. Hence, I am wondering what's going on and how to make the numeric formats permantenly using these lines of code?
MRE
df <- tribble(~date, ~value,
"2017-01-01", 1,
"2017-01-02", 2,
"2017-01-02", 3,
"2017-01-03", 4,
"2017-01-03", NA,
"2017-01-04", 6,
"2017-01-09", 9) %>%
arrange(date) %>%
mutate(to_date=cumsum(value))