1
jnk <- data.table(a=c('1,2,3,4,5','1,2,3','2,3'),b=c('5,2,3','4,2',3))

Can I do a split using both the columns a and b? If we use [Undesired_Output][1] H= cSplit(jnk,"a",",","long"), we get the output as shown in image 1. However I want the output where my dataframe looks like shown below after execution of the following commands:

b=c(rep(5,5),rep(2,5),rep(3,5),rep(4,3),rep(2,3),3,3)

a=c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,1,2,3,2,3)

p=data.frame(A=a,B=b) 
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
Udit
  • 21
  • 1
  • 2
    Try `cSplit(jnk, "a", ",", "long")[, cSplit(.SD, "b", ",", "long")]` or with `separate_rows` `separate_rows(jnk, "a") %>% separate_rows("b")` – akrun Mar 17 '18 at 12:15
  • Thanks buddy. cSplit(jnk, "b", ",", "long")[, cSplit(.SD, "a", ",", "long") worked. Can you tell me what is this .SD that we are passing in the 1st argument? – Udit Mar 17 '18 at 12:39
  • FYI, if you install [V2 of "splitstackshape" (in development)](https://github.com/mrdwab/splitstackshape/tree/v2.0) you would be able to simply do: `cartesian_split(jnk, names(jnk))` to get your output. – A5C1D2H2I1M1N2O1R2T1 Mar 31 '18 at 09:13

0 Answers0