I am having problems replacing values in a column i a table with values from another table/list. I have the following example dataset 'df':
type col2 col3
A NA blue
A America blue
A Nam blue
B NA red
B '' red
B 'Nam' red
And I have this simplified table, with the temperatures for each value in column 'type':
type temp
A hot
B cold
So, I am trying to replace and/or fill (if na=TRUE) the values for the initial data.frame (df$type) with the correspondent data from list and obtain this result:
type new_Col2 col3
A hot blue
A hot blue
A hot blue
B cold red
B cold red
B cold red
I used the normal commands for replacing/fill:
df <- df %>%
mutate(type = replace(type, type == 'A', 'hot'),
type = replace(type, type == 'B', 'cold'))
However, my real data have +100.000 rows (and 15,000 different 'types'), and I am stuck trying to solve how I can do the replacement recursively.
The problem is that the length of each data.frame is different, so I can't replace each value using the 'mutate/replace' commands.
Someone can help me to solve this?
Any help would be appreciated. Thanks!