I\'m new to R, and am working on a side project for my own purposes. I have this data (reproducable dput of this is at the end of the question):
X
Using rowid() from the data.table-package along with dcast:
require(data.table)
dcast(dt, user + rowid(user, state) ~ state, value.var="datetime")
# user user_1 joined left
# 1: User1 1 2016-02-19 19:13:26 2016-02-19 19:13:32
# 2: User1 2 2016-02-19 19:21:33 2016-02-19 19:25:26
# 3: User1 3 2016-02-19 19:35:38 2016-02-19 19:42:16
# 4: User1 4 2016-02-19 19:44:15 2016-02-19 19:47:59
# 5: User1 5 2016-02-19 19:48:55 2016-02-19 19:51:06
# 6: User1 6 2016-02-19 19:52:40
# 7: User2 1 2016-02-19 19:21:18 2016-02-19 19:30:30
# 8: User3 1 2016-02-19 19:53:15 2016-02-19 20:02:26
# 9: User3 2 2016-02-19 20:02:34
# 10: User3 3 2016-02-19 20:13:48