0

I have data frame Tableas follows:

Date   Task
1      575171-02-1
2      571120-01-7, 712102-01-1, 712102-02-1, 712202-01-1
3      535105-01-5, 532137-01-2
4      572036-01-6, 532170-01-2

I want output like this:

Task               Date
575171-02-1          1
575171-02-1          1
712102-01-1          1
712102-02-1          1
712202-01-1          2 
535105-01-5          3
...

I tried to create new data frames in loop of loop


    for (i in 1:nrow(Table)) {

      X<-strsplit(Table$Task[i],", ")

      for (j in 1:length(X))
      { Date<-Table$Date[i]
        Task<-X[j]


I don't know how can I create new data frame in second loop, so when i turn to new loop it will not be overwritten

Jenny Pham
  • 181
  • 7
  • You can use `separate_rows(df, Task)` – akrun Jul 15 '19 at 14:02
  • Sorry, the `Task` has string format like: 575171-02-1, 571120-01-7. so the command does not work as my output – Jenny Pham Jul 15 '19 at 14:14
  • But, you sshowed an example with an expected output that works with the code. Also, your code with `strsplit` suggests the issue relating to the example – akrun Jul 15 '19 at 14:15
  • Sorry, I already edit my examples. Because of the format so I have to use the `strsplit` – Jenny Pham Jul 15 '19 at 14:18
  • In the `separate_rows, there is a `sep` argument, use that `separate_rows(df, Task, sep=",")` – akrun Jul 15 '19 at 14:19

0 Answers0