i need to create an empty data.table, with a variable length. For example, i will be given that n = 2
amd m = 12
, then i want the table to have columns such as:
name, ID, nickname, start_1, start_2, count_1, count_2, value_<n>_month_<m>
(value_<n>_month_<m>
is repeated m
x n
times)
i get columns: name, ID, nickname, start_1, start_2, start_3 count_1, count_2, count_3
by using the following code:
VarStart <- setnames(setDF(lapply(integer(K), function(...) character(0L))),
paste0("start", 1:K))
NewTable <- cbind(NewTable, VarStart)
VarCount <- setnames(setDF(lapply(integer(K), function(...) character(0L))),
paste0("start", 1:K))
NewTable <- cbind(NewTable, VarCount)
borrowed from here.
But how can i crete columns for variables with both n
and m
in the column name?
Is there a nicer way to what i already have?