0

Relatively new to R... I am trying to create a column in a data frame (df1, that currently has a single column), in which each new value will be determined based on the value in the existing column - by referring to another (reference) data frame (df2) that has two columns and is effectively like a hash. I was trying to avoid making an actual has because that doesn't seem to be the done thing in R.

So, the reference dataframe df2 looks like this:

col1 col2
A 71
R 156
N 114
D 115
...

The values in col1 only occur once each in the column

The data frame df1 that I'm working on might look like this (for example):

D
D
R
A
N
A
D
...

So, for each row in df1, I'd like to create a new column where the script takes the col1 value from df1, looks up df2, finds the matching value in col1, and then takes the corresponding value from col2 and places it in the new column in df1. So, if it worked, I'd end up with df1 looking like this:

D 115
D 115
R 156
A 71
N 114
A 71
D 115
...

0 Answers0