0

Is there an R function to convert the entire data frame to numeric. My data frame contains only numeric variables but when queried with r with the is.numeric code, it comes as false.

  • 1
    Read about `?type.convert`. Also, please share a minimal reproducible example? – markus Feb 18 '20 at 19:32
  • 1
    Does this answer your question? [How to convert entire dataframe to numeric while preserving decimals?](https://stackoverflow.com/questions/26391921/how-to-convert-entire-dataframe-to-numeric-while-preserving-decimals) – Brydenr Feb 18 '20 at 21:09

2 Answers2

2

We can use

df1[]<-  lapply(df1, as.numeric)
akrun
  • 674,427
  • 24
  • 381
  • 486
1

With dplyr :

mutate_all(data, function(x) as.numeric(as.character(x)))

Gainz
  • 1,551
  • 4
  • 21