Changing column types with dplyr

后端 未结 3 1335
情书的邮戳
情书的邮戳 2021-02-11 03:05

I need some help tidying my data. I\'m trying to convert some integers to factors (but not all integers to factors). I think I can do with selecting the variables in question

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-11 04:10

    Honestly, I'd do it like this:

    library(dplyr)
    
    df = data.frame("LOC_ID" = c(1,2,3,4),
                    "STRS" = c("a","b","c","d"),
                    "UPC_CDE" = c(813,814,815,816))
    
    df$LOC_ID = as.factor(df$LOC_ID)
    df$UPC_CDE = as.factor(df$UPC_CDE)
    

提交回复
热议问题