Two of R-Studio masters kindly helped me to find duplicated responses using this:
source.data <-
data.frame(
stringsAsFactors = FALSE,
VRN = c("A8PWA","A8WTW","A9CGB",
"A9CGB","AJ18SHZ","AJ18VJU","AJ18VJU","AJ18VJU"),
NPSResponseDate = c("2021-09-28 14:21:05",
"2021-10-14 13:04:01","2021-10-29 15:44:45",
"2021-12-15 11:21:59","2022-05-09 13:01:34","2022-04-21 12:50:06",
"2022-05-27 20:52:05","2022-07-15 23:34:26")
)
result <- source.data %>%
group_by(VRN) %>%
arrange(NPSResponseDate)%>%
mutate(Sequence = row_number(),
Duplicated.VRN=n()>1) %>%
ungroup() %>%
arrange(VRN, NPSResponseDate)
but I personally think, it would be very useful for many R users to be able to count days (or hours) between responses (based on the NPSResponseDate) rather than just flagging respondents with repeated responses.
As a result, I would need something like this:
result <- data.frame(
stringsAsFactors = FALSE,
VRN = c("A8PWA","A8WTW","A9CGB",
"A9CGB","AJ18SHZ","AJ18VJU","AJ18VJU","AJ18VJU"),
NPSResponseDate = c("2021-09-28 14:21:05",
"2021-10-14 13:04:01","2021-10-29 15:44:45",
"2021-12-15 11:21:59","2022-05-09 13:01:34","2022-04-21 12:50:06",
"2022-05-27 20:52:05","2022-07-15 23:34:26"),
Days_between = c(NA,NA,46.8175263079029,
46.8175263079029,NA,36.3347094561032,36.3347094561032,
36.3347094561032)
)
result
Is it possible to do it in R?