EDIT: Rephrasing: The situation described can be the result of data extraction from different statistical programs, that may produce separately csv files with (a) factors levels and (b) their corresponding assigned "numerical" values.
1) I may have many factor variables e.g. gender, age ranges and these factor variables have levels e.g. male/famele, 18-30/31-40 etc. 2) These levels are assigned to some numbers, either ordered or not. 3) The factor/level dataframe is one dataframe / dataset. The assigned to factor levels dataset is a separated dataframe. 4) I would like to join these two datasets into a single one. This means that the ordered factor levels must be retained and correctly assigned to their corresponding numbers.
So Factor levels and their assigned numbers are kept into two different datasets (e.g. csv files). These two dataframes must be "merged".
How can I do that? p.s. There is a cmmon ID variable between these two datasets.
d1_levels d2_levels d3_levels
1 2 2 0
2 0 1 2
3 1 2 1
4 2 2 2
d1_labels d2_labels d3_labels
1 boy east <3kg
2 dont know south 3kg
3 girl east >3kg
4 boy east 3kg
I would like to have the same result for d1_labels, as the result of the below R command
dataset$d1_labels<- factor(d1_levels, levels = c(0,1,2), labels = c("dont know", "girl", "boy"))