I\'m new to R programming and I\'m stuck on the example below.
Basically I have two data sets:
dataset1:
ID Category
1 CatZ
Using a combination of base R match
function and data.table's set
function:
matchinds = na.omit(match(dataset1$ID,dataset2$ID)) # this will give index of dataset2$ID where values of dataset1$ID were equal to values of dataset2$ID
set(x=dataset1,i=matchinds,j="Category",value=dataset2$category[matchinds]) #this will set values at matching indexes in dataset1 Category column equal to Category column matching index values in dataset2