I'm using this procedure to convert categorical values to numeric values using levels and merge from reshape2 library. (just two columns shown for the sake of brevity)
data
printerM user
RICOH Pam
CANON Clara
TOSHIBA Joe
RICOH Fred
CANON Clark
printers.df <- data.frame(printers=unique(data$printerM))
numbers.df <- data.frame(numbers=1:length(unique(data$printerM))
printers.table <- as.data.frame(cbind(printers.df, numbers.df))
library(reshape2)
new.data<- merge(data, printers.table)
new.data$printers <- NULL
new.data
printer user numbers
RICOH Pam 1
CANON Clara 2
TOSHIBA Joe 3
RICOH Fred 1
CANON Clark 2
The issue is I got 34 columns and I'm not very happy of writing the same code 34 times, so I suppose this can be handled by:
1.- converting my code into a function 2.- using an existing R function
Not very versed on converting my R code into a function, and I don't know if this kind of transformation is available in any library.
Anyway, any hint will be much appreciated.