I have this data which is basically a matrix but is in data.table format:
Lets call this matA:
Date compA compB compC
200101 1 2 3
200102 2 4 1
How do I make the matrix into a database type in data.table?
Lets call this dataset dtB:
Date Company Data
200101 compA 1
200101 compB 2
200101 compC 3
200102 compA 2
200102 compB 4
200102 compC 1
I have thought about a very stupid way to make a list of companies:
comp= as.data.table(c("compA", "compB", "compC"))
date= as.data.table(rep(matA[1,1],3))
data= as.data.table(matA[1,])
dtb= date[,Company := comp]
dtb= dtb[, Data := data]
And obviously I can at most get the data in date 200101. To get 200102, I write a for loop. Then, merge both 200101 and 200102 into dtB according to the colnames.
Is there a clever way to do this in data.table? Many thanks