Convert data.frame columns from factors to characters

前端 未结 18 1454
时光取名叫无心
时光取名叫无心 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:18

    You should use convert in hablar which gives readable syntax compatible with tidyverse pipes:

    library(dplyr)
    library(hablar)
    
    df <- tibble(a = factor(c(1, 2, 3, 4)),
                 b = factor(c(5, 6, 7, 8)))
    
    df %>% convert(chr(a:b))
    

    which gives you:

      a     b    
       
    1 1     5    
    2 2     6    
    3 3     7    
    4 4     8   
    

提交回复
热议问题