This is merging DB.SpotifyMeta with DB.raw Before this point, I should have identified a `wcols` # ----------------------------- # Its not clear what I was doing here. It looks like I was taking a subset of DB.raw namely, just dailycounts, by upc, date, artist, mkt_priority (just the unqiue rows, so much smaller than DB.raw) Then merging that *fully* with DB.SpotifyMeta to create DB.merged # ----------------------------- # # ----------------------------- # metcols <- c("t.DailyCount.byupc", "u.DailyCount.byupc") colsUsing <- c("upc", "download_date", "artist_country", "mkt_priority", "label_priority", "minDate.byupc", "maxDate.byupc") setkeyIfNot(DB.SpotifyMeta, "upc") setkeyIfNot(DB.raw, "upc", "download_date") # confirm this # DB.merged <- merge(DB.raw[,lapply(.SD, sum, na.rm=TRUE), .SDcols=metcols, keyby=colsUsing] , DB.SpotifyMeta, all=TRUE) colsUsing <- intersect(colsUsing, names(DB.raw)) dailytotals <- unique( DB.raw[, .SD, .SDcols=c(colsUsing, metcols)] ) DB.merged <- merge(dailytotals, DB.SpotifyMeta, all=TRUE) # ----------------------------- # ## Drop NA startDates DB.merged <- DB.merged[!is.na(startDate)] # we dont need this as a stand alone DT, just for easier code reading Key7Day <- DB.merged[, list(startDate7=seq7Days(startDate)), by=list(upc, startDate)][, list(upc, startDate7)] simply <- unique(DB.merged[Key7Day, c(lapply(.SD[, metcols, with=FALSE], sum, na.rm=TRUE), .SD[, !metcols, with=FALSE]) , .SDcols=c(metcols, "genre", wcols)]) # ----------------------------- # as.Date(15720, origin=origin) DB.merged[CJ(u, )] is(DB.raw[["download_date"]]) DB.merged[1, c(upc, startDate)] is(DB.merged[["startDate"]]) DB.merged[1, seq.Date(startDate)] ... then what?