Convert data.frame columns from factors to characters

前端 未结 18 1142
时光取名叫无心
时光取名叫无心 2020-11-22 04:43

I have a data frame. Let\'s call him bob:

> head(bob)
                 phenotype                         exclusion
GSM399350 3- 4- 8- 25- 44+         


        
18条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 05:26

    I typically make this function apart of all my projects. Quick and easy.

    unfactorize <- function(df){
      for(i in which(sapply(df, class) == "factor")) df[[i]] = as.character(df[[i]])
      return(df)
    }
    

提交回复
热议问题