r - Fill sequence by factor -
i need fill $year missing values of sequence factor of $country. $count column can padded out 0's.
country year count 1 1 2 1 4 2 b 1 1 b 3 1 so end with
country year count 1 1 2 1 3 0 4 2 b 1 1 b 2 0 b 3 1 hope that's clear guys, in advance!
library(data.table) # d original data.frame setdt(d) foo <- d[, .(year = min(year):max(year)), country] res <- merge(d, foo, all.y = true)[is.na(count), count := 0] 
Comments
Post a Comment