Skip to contents

Creates a duration variable using the start and end time of the survey

Usage

add_duration(
  dataset,
  duration_column = "duration",
  uuid_column = "uuid",
  start_column = "start",
  end_column = "end"
)

Arguments

dataset

dataset to add the duration

duration_column

the name of the duration variable that will be created.

uuid_column

uuid column in the dataset. Default is uuid.

start_column

start time of the survey, in KOBO format (e.g "2021-07-14T14:02:24.955+03:00")

end_column

end time of the survey, in KOBO format (e.g "2021-07-14T14:03:28.955+03:00")

Value

the clean dataset with 6 new columns: duration, start_date, start_time, end_date, end_time, days_diff

Examples


test_data <- data.frame(
  start = c(
    "2021/07/13 11:25:49", "2021/07/13 12:36:16",
    "2021/07/13 10:21:10", "2021/07/13 10:54:07", "2021/07/13 11:18:45"
  ),
  end = c(
    "2021/07/13 12:02:39", "2021/07/13 13:20:17",
    "2021/07/13 10:53:42", "2021/07/13 11:28:58", "2021/07/13 11:55:24"
  ),
  uuid = 1:5
)

test_data_w_duration <- test_data |>
  add_duration() 

test_data_w_duration |>
  knitr::kable()  
#> 
#> 
#> |start               |start_date |start_time  |end                 |end_date   |end_time    | uuid|days_diff | duration|
#> |:-------------------|:----------|:-----------|:-------------------|:----------|:-----------|----:|:---------|--------:|
#> |2021/07/13 11:25:49 |2021/07/13 |685.82 mins |2021/07/13 12:02:39 |2021/07/13 |722.65 mins |    1|0 days    |    36.83|
#> |2021/07/13 12:36:16 |2021/07/13 |756.27 mins |2021/07/13 13:20:17 |2021/07/13 |800.28 mins |    2|0 days    |    44.01|
#> |2021/07/13 10:21:10 |2021/07/13 |621.17 mins |2021/07/13 10:53:42 |2021/07/13 |653.70 mins |    3|0 days    |    32.53|
#> |2021/07/13 10:54:07 |2021/07/13 |654.12 mins |2021/07/13 11:28:58 |2021/07/13 |688.97 mins |    4|0 days    |    34.85|
#> |2021/07/13 11:18:45 |2021/07/13 |678.75 mins |2021/07/13 11:55:24 |2021/07/13 |715.40 mins |    5|0 days    |    36.65|
  
## Second test
test_data_kobo_time <- data.frame(
  `X.U.FEFF.start` = c(
    "2021-07-13T11:25:49.543+03:00",
    "2021-07-13T12:36:16.316+03:00",
    "2021-07-13T10:21:10.337+03:00",
    "2021-07-13T10:54:07.394+03:00",
    "2021-07-13T11:18:45.521+03:00"
  ),
  end = c(
    "2021-07-14T12:02:39.269+03:00",
    "2021-07-13T13:20:17.815+03:00",
    "2021-07-13T10:53:42.662+03:00",
    "2021-07-13T11:28:58.295+03:00",
    "2021-07-13T11:55:24.366+03:00"
  ),
  uuid_column = 1:5)


test_data_kobo_time_w_duration <- test_data_kobo_time |>
                   add_duration(start_column = "X.U.FEFF.start")


test_data_kobo_time_w_duration |>
  knitr::kable()  
#> 
#> 
#> |X.U.FEFF.start                |start_date |start_time  |end                           |end_date   |end_time    | uuid_column|days_diff | duration|
#> |:-----------------------------|:----------|:-----------|:-----------------------------|:----------|:-----------|-----------:|:---------|--------:|
#> |2021-07-13T11:25:49.543+03:00 |2021-07-13 |685.82 mins |2021-07-14T12:02:39.269+03:00 |2021-07-14 |722.65 mins |           1|1 days    |  1476.83|
#> |2021-07-13T12:36:16.316+03:00 |2021-07-13 |756.27 mins |2021-07-13T13:20:17.815+03:00 |2021-07-13 |800.28 mins |           2|0 days    |    44.01|
#> |2021-07-13T10:21:10.337+03:00 |2021-07-13 |621.17 mins |2021-07-13T10:53:42.662+03:00 |2021-07-13 |653.70 mins |           3|0 days    |    32.53|
#> |2021-07-13T10:54:07.394+03:00 |2021-07-13 |654.12 mins |2021-07-13T11:28:58.295+03:00 |2021-07-13 |688.97 mins |           4|0 days    |    34.85|
#> |2021-07-13T11:18:45.521+03:00 |2021-07-13 |678.75 mins |2021-07-13T11:55:24.366+03:00 |2021-07-13 |715.40 mins |           5|0 days    |    36.65|