The following should give you the result you want:
panelFull[panel, CellID := CellID, on = "OutletID"]
For the provided datasets this will result in a column with only NA
-values as there are no matching OutletID
's between the two datasets. Therefore I slightly adapted the content of the panelFull
dataset (you can find a dput
at the end of this answer). The join then results in:
> panelFull
OutletID pno CellID
1: CP0001 204 NA
2: CP0001 205 NA
3: CP0001 206 NA
4: CP0001 207 NA
5: CP0001 208 NA
6: CP0001 209 NA
7: CP0001 210 NA
8: CP0001 211 NA
9: CP0001 212 NA
10: CP0001 213 NA
11: CP0001 214 NA
12: CP0001 215 NA
13: CP0006 204 NA
14: CP0006 205 NA
15: CP0006 206 NA
16: M60700 215 1268
Used data:
panelFull <- structure(list(OutletID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L), .Label = c("CP0001", "CP0006", "M60700"), class = "factor"), pno = c(204L, 205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L, 204L, 205L, 206L, 215L)), .Names = c("OutletID", "pno"), class = c("data.table", "data.frame"), row.names = c(NA, -16L))
panel <- structure(list(Period = c(215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L), CellID = c(1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L, 1268L), OutletID = structure(1:15, .Label = c("M44600", "M44800", "M45100", "M45200", "M45300", "M46900", "M48400", "M51000", "M51500", "M51600", "M53700", "M57000", "M59400", "M60200", "M60700"), class = "factor"), ACV = c(9563317L, 8966339L, 7043924L, 9013918L, 10009468L, 22148703L, 18661734L, 8531347L, 9125734L, 8575727L, 12148614L, 9678589L, 17261166L, 7939758L, 6840897L)), .Names = c("Period", "CellID", "OutletID", "ACV"), class = c("data.table", "data.frame"), row.names = c(NA, -15L))