I want to approximate how much time is spent in a program per user. My data is a log of all activity in the program. I have calculated the time difference between each log entry.
I am assuming that if you have no activity for >60 seconds, you are no longer using the program. Hence I want to summarize the length of each 'session'. In other words, I want to accumulate the time difference between each log, until the time difference is higher than 60, then I want to save the final tally and start over. Ideally, if there is just one entry (such as #21 and #23) before the tally is reset, I am assuming they used the program for 5 seconds.
If you have more clever ways to approximate time spent in the program, I would be very happy to hear your suggestions!
Intended outcome
User <- c("Bruger-138-450-251", "Bruger-138-450-251", "Bruger-138-450-251", "Bruger-138-450-251", "Bruger-338-978-988", "Bruger-338-978-988", "Bruger-338-978-988", "Bruger-338-978-988")
Time_spent <- c("322.55", "145.447", "88.88700008", "5", "5", "6.523000002", "92.62900019", "53.3499999")
intended_output <- data.frame(User, Time_spent)
Data snippet:
DF1 <- structure(
list(
User = c(
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-138-450-251",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988",
"Bruger-338-978-988"
),
Activity = c(
3,
2,
2,
6,
6,
2,
2,
6,
3,
6,
3,
3,
2,
5,
6,
4,
2,
1,
5,
2,
2,
2,
2,
3,
5,
3,
5,
2,
2,
4,
6,
1,
3,
3,
5,
5,
2
),
Time = structure(
c(
1643268505.478,
1643268563.552,
1643268620.463,
1643268634.955,
1643268679.546,
1643268856.269,
1643268881.907,
1643268886.102,
1643269006.059,
1643269032.07,
1643269061.255,
1643269073.864,
1643269096.987,
1643269110.895,
1643269139.23,
1643269151.506,
1643269749.455,
1643269779.843,
1643269838.342,
1643269992.661,
1643270125.465,
1643268540.04,
1643268582.205,
1643268693.839,
1643268700.362,
1643269168.237,
1643269169.208,
1643269171.457,
1643269202.264,
1643269204.619,
1643269206.852,
1643269210.238,
1643269249.979,
1643269260.866,
1643269544.183,
1643269597.374,
1643269597.533
),
tzone = "UTC",
class = c("POSIXct", "POSIXt")
),
Difference = structure(
c(
NA,
58.0739998817444,
56.9110000133514,
14.4919998645782,
44.5910000801086,
176.723000049591,
25.6380000114441,
4.1949999332428,
119.957000017166,
26.0110001564026,
29.1849999427795,
12.6089997291565,
23.1230001449585,
13.9079999923706,
28.335000038147,
12.2760000228882,
597.948999881744,
30.3880000114441,
58.4990000724792,
154.319000005722,
132.804000139236,
NA,
42.164999961853,
111.634000062943,
6.52300000190735,
467.875,
0.970999956130981,
2.24900007247925,
30.8069999217987,
2.35500001907349,
2.23300004005432,
3.38599991798401,
39.7410001754761,
10.8870000839233,
283.316999912262,
53.1909999847412,
0.158999919891357
),
units = "secs",
class = "difftime"
)
),
class = c("grouped_df",
"tbl_df", "tbl", "data.frame"),
row.names = c(NA,-37L),
groups = structure(
list(
User = c("Bruger-138-450-251", "Bruger-338-978-988"),
.rows = structure(
list(1:21, 22:37),
ptype = integer(0),
class = c("vctrs_list_of",
"vctrs_vctr", "list")
)
),
row.names = c(NA,-2L),
class = c("tbl_df",
"tbl", "data.frame"),
.drop = TRUE
)
)
I have looked at the following posts with no success: