0

I have a question in the utilizing of Reshape library and melt in R.

Suppose I have the following data phase

ID Visit    Date_1     Time_1     Date_2      Time_2        Date_3     Time_3 
1     1   9/1/2019     10:00      9/2/2019    10:00         9/3/2019     10:00
1     2   10/1/2019    10:00      10/2/2019   10:00         10/3/2019    10:00

What is the best solution to make it so that the each ID and Visit has a separate row for each visit Date and Time like so:

ID     Visit    Date         Time 
1        1       9/1/2019     10:00  
1        1       9/2/2019    10:00 
1        1       9/3/2019    10:00 
1        2       10/1/2019   10:00
1        2       10/2/2019   10:00  
1        2       10/3/2019    10:00

I was thinking of merging the Date_1 and Time_1 to one column then melt according to ID and Visit, subset, then bind by row and sort. I was wondering if there were an easier method using reshape library. Thanks!

A. Suliman
  • 12,235
  • 5
  • 20
  • 34
Monklife
  • 177
  • 3
  • 9

0 Answers0