I was looking for a way to change the class of variables in one data frame using a link from another data frame that has class information for each variable.
I have data containing about 150 variables. All variables are in character format. Now I want to change the class of each variable depending on its type. To do this, we created a separate data frame containing class information for each of the variables. Let me explain an example data frame.
Consider my original data frame as df with 5 variables -
df <- data.frame(A="a",B="1",C="111111",D="d",E="e")
Now we have another "variable_info" data frame, which contains only 2 variables, one "variable name" and another "variable_class".
variable_info <- data.frame(variable_name=c("A","B","C","D","E"),variable_class=c("character","integer","numeric","character","character"))
Now, using the variable_information data frame, I want to change the class for each of the variables in df so that their class is specified in "variable_info $ variable_class", associating the name of the variable with "variable_info $ variable_name"
How to do this for a data frame? Would it be useful to do this in data.table? How to do this in data.table?
Thank!
Prasadam