0
# Origin Table like below : df
Col1                         Col2                       Keep1  Keep2
" "";2017-01-01;2016-09-17"  "201-101;201-102;201-103"  John   Apple
"2018-01-01;"";2012-09-17"   " "";201-102;203-640"      Tom    Orange
"2015-04-11;2016-08-12"      "301-190;302-801"          Mary   Banana
"2017-01-01"                 "401-031"                  Dan    Beer

# Desired Table : df2
Col1                        Col2                        Keep1  Keep2
""                          201-101                     John   Apple
2017-01-01                  201-102                     John   Apple
2016-09-17                  201-103                     John   Apple
2018-01-01                  ""                          Tom    Orange
""                          201-102                     Tom    Orange
2012-09-17                  203-640                     Tom    Orange
2015-04-11                  301-190                     Mary   Banana
2016-08-12                  302-801                     Mary   Banana
2017-01-01                  401-031                     Dan    Beer

Targeted Split Columns have same numbers of elements in one cell connected by " ; ".

Want to split them parallelly :

  • Col1 1st Element -- Col2 1st Element
  • Col1 2nd Element -- Col2 2nd Element
  • Col1 3rd Element -- Col2 3rd Element

while copying the others cols .

library(tidyverse)
separate_rows

exactly perform this but ,

  • Col1 1st Element -- Col2 1st Element ,2nd Element , 3rd Element
  • Col1 2st Element -- Col2 1st Element ,2nd Element , 3rd Element
  • Col1 3st Element -- Col2 1st Element ,2nd Element , 3rd Element....

it is copying all the patterns when specify multi cols to split .

How to splitting multi cols while arranging them in way corresponding to every element ?

  • "" in the dataset exactly means "" like what R console display , they can only be detected by grepl("",x) or < 0 , < 1 .Not Null,Na,NaN ,\n,\s .e.t.c. This issue also drive me crazy .
rane
  • 901
  • 4
  • 12
  • 24
  • 2
    simplest way could be `library(splitstackshape); cSplit(df, c("Col1", "Col2"), ";", direction = "long") ` – Ronak Shah May 30 '18 at 08:21
  • 1
    Thankyou ! I don't even know there is the package like this exist ! – rane May 30 '18 at 08:41
  • Oh , now i noticed that `cSplit` is not exactly doing what i want. Because its create the NA -- pad -- rows according to the highest splitted group's numbers of rows appending the others smaller group . That why my R s crushing as`cSplit` creating more pad rows -- origin dataset rows: 2M x the top splitted numbers. (If they don't have same number of elements) – rane Jun 01 '18 at 07:10
  • Please update your post with the issue you are facing using current solution. What is the output it is giving using current approach and what is your expected output. – Ronak Shah Jun 01 '18 at 07:24

0 Answers0