r transform as factor code example Example: r - transform as factor df$myvar <- as.numeric(as.character(df$myvar)) df$myvar <- as.factor(df$myvar)