-3

I have a dataset where the data is structured this way

dt<- data.table(
item=c("G,S,GS","G,S"),
timePeriod=c("1995:2000","2006),
refArea = c("DE,SE","DE,SE,SK,SI")
)

the result is something like:

test2 <- data.table(
  item=c("G","G","S","G","G","G","G"),
  timePeriod=c("1995","1995","1995","1995","2006","2006","2006"),
  refArea = c("DE","SE","DE","SE","DE","SE","SK")
)

I did not put all the lines. Indeed I think I should use expand.grid somewhere.

How could I do that? Thanks

IRT
  • 209
  • 2
  • 11
  • 1
    It's not clear what you expect out of this. Can you show what your expected output is? For instance, are you hoping that any of the delimited values are expanded, such as `"G,S,GS"` --> `c("G", "S", "GS")` and `"1995:2000"` --> `c(1995,1996,1997,...,2000)`? – r2evans Oct 11 '21 at 15:37
  • Or do you just need `do.call(expand.grid, dt)`? – r2evans Oct 11 '21 at 15:37
  • Maybe start by fixing your reproducible example. – s_baldur Oct 12 '21 at 10:40

1 Answers1

0

thanks r2evans, indeed it will make it.

do.call(expand.grid, dt)
#     item timePeriod     refArea
# 1 G,S,GS  1995:2000       DE,SE
# 2    G,S  1995:2000       DE,SE
# 3 G,S,GS       2006       DE,SE
# 4    G,S       2006       DE,SE
# 5 G,S,GS  1995:2000 DE,SE,SK,SI
# 6    G,S  1995:2000 DE,SE,SK,SI
# 7 G,S,GS       2006 DE,SE,SK,SI
# 8    G,S       2006 DE,SE,SK,SI
r2evans
  • 141,215
  • 6
  • 77
  • 149
IRT
  • 209
  • 2
  • 11
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Muhammedogz Oct 12 '21 at 11:37