R change all columns of type factor to numeric

前端 未结 2 1590
执笔经年
执笔经年 2020-12-13 07:26

I have a data frame that is 100 X 100. There are 30 columns that are factors. Is there a way to switch only factor-type columns to numeric type without affecting the other

2条回答
  •  一个人的身影
    2020-12-13 07:41

    See R-FAQ 7.10 at cran.r-project.org http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f

    ALWAYS do as.numeric(as.character(some_Factor)) or you will be sorry.

提交回复
热议问题