Batch convert columns to numeric type

前端 未结 6 2012
眼角桃花
眼角桃花 2021-01-01 11:20

I have a dataframe with a bunch of columns that I need to convert to the numeric type. I have written the following code to try to do this, however it is saying the replacem

6条回答
  •  生来不讨喜
    2021-01-01 11:40

    Just pass the columns you want as a data frame d into the following:

    data.frame(apply(d, 2, as.numeric))
    

    This goes column by column and converts each into a numeric. Then just change your row-names and column-names accordingly.

提交回复
热议问题