I am fairly new to R and am trying to replace values in my data.frame named df from corresponding values in a data.table called dtb. My data.table is simply a count of all unique values in my data.frame and looks as such:
df
  fruits
1 apple
2 pear
3 banana
4 apple
5 banana  
dtb
     fruits    N
1    apple     2
2    pear      1
3    banana    2
I wish to replace my original data.frame values with the counts based upon the name. For output would look like this:
df
  fruits
1 2
2 1
3 2
4 2
5 2 
I have tried to look through observations and check if it is in the fruits column of the data table but am struggling. Could anyone help me here? Thanks
 
    