Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • Is there any way to do this for multiple columns at once? For instance 3 columns that each have strings separated by ";" with each column having the same number of strings. i.e. data.table(id= "X21", a = "chr1;chr1;chr1", b="123;133;134",c="234;254;268") becoming data.table(id = c("X21","X21",X21"), a=c("chr1","chr1","chr1"), b=c("123","133","134"), c=c("234","254","268")) ? Commented Jan 19, 2019 at 1:39
  • 1
    wow just realized it already works for multiple columns at once - this is amazing! Commented Jan 19, 2019 at 1:50
  • @Reilstein could you share how you adapted this for multiple columns? I have the same use case, but unsure how to go about it. Commented Jun 14, 2019 at 6:01
  • 1
    @Moon_Watcher Method 1 in the answer above already works for multiple columns, which is what I thought was amazing. setDT(dt)[,lapply(.SD, function(x) unlist(tstrsplit(x, ";",fixed=TRUE))), by = ID] is what worked for me. Commented Jun 14, 2019 at 19:38
  • 2
    FYI separate_rows is deprecated in favor of separate_longer_delim now Commented Mar 13, 2023 at 11:12