What is the best way to add a sequence column in a data.table depending on a fixed selected value and a value defined by a column. The following example ilustrates the input and desired output:
library(data.table)
# Input
# Add a column sequence till 7 starting from the value of column V2.
dt <- data.table(c("A","D","H"), c(2, 4, 5))
# Desired Ouput
dt <- data.table(c(rep("A", 6), rep("D", 4), rep("H", 3)), new_column = c(2:7, 4:7, 5:7))
dt