We could do this with a version of devel data.table , which can accept multiple value.var columns. Installation instructions for the devel version: here
We convert 'data.frame' to 'data.table' ( setDT(df) ), create a sequence variable ('ind') using grouping variables ('id1', 'id2', 'info'), and dcast from ' long 'to' wide ', specifying value.var as "action_time" and "action_comment".
library(data.table)
Or use reshape from base R We create a sequence variable ('ind') with ave and reshape to change the format of 'long' to 'wide'.
df$ind <- with(df, ave(seq_along(id1), id1, id2, info, FUN=seq_along)) reshape(df, idvar=c('id1', 'id2', 'info'),timevar='ind', direction='wide')
data
df <- structure(list(id1 = c(1L, 1L, 1L, 2L, 2L), id2 = c("a", "a", "a", "b", "b"), info = c("info1", "info1", "info1", "info2", "info2"), action_time = c("time1", "time2", "time3", "time4", "time5"), action_comment = c("comment1", "comment2", "comment3", "comment4", "comment5")), .Names = c("id1", "id2", "info", "action_time", "action_comment"), class = "data.frame", row.names = c(NA, -5L))