Q:

How to gather series of columns with data into rows

I'm just trying to get my head around tidying my data and I have this problem:
I have data as follows:
ID  Tx1  Tx1Date   Tx1Details Tx2  Tx2Date   Tx2Details Tx3  Tx1Date   Tx1Details  
1   14   12/3/14      blabla  1e   12/5/14   morebla   r    14/2/14   grrr
2   23   14/5/16      albalb  342  1/4/5     teeee     s    5/6/17    purrr

I want the data to be in the format
ID Tx  TxDate  TxDetails
1 14   12/3/14   blabla
1 1e   12/5/14   morebla
1 r    14/2/14   grrr
2 23   14/5/16   albalb 
2 342  1/4/5     teeee
2 s    5/6/17    purrr

I have used
library(tidyr)
library(dplyr)
NewData<-mydata %>% gather(key, value, "ID", 2:10)

but I'm not sure how to rename the columns as per the intended output to see if this will work

A:

The data.table package handles this pretty well. 
library(data.table)
setDT(df)
melt(df, measure = list(Tx = grep("^Tx[0-3]$", names(df)), 
                        Date =  grep("Date", names(df)), 
                        Details = grep("Details", names(df))),
         value.name = c("Tx", "TxDate", "TxDetails"))

Or more concisely 
melt(df, measure = patterns("^Tx[0-3]$", "Date", "Details"),
         value.name = c("Tx", "TxDate", "TxDetails"))

