Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Consider the consecutive value in the data

$
0
0

I have a data with 3 columns ID, Time and Type; I Need to add a column called "categroy" and the sample data with output is given below:

> dput(DF1)
structure(list(ID = c("104 - 2019-06-03", "104 - 2019-06-03", 
"104 - 2019-06-03", "104 - 2019-06-03", "104 - 2019-06-03", "104 - 2019-06-03", 
"104 - 2019-06-03", "104 - 2019-06-03", "104 - 2019-06-03", "104 - 2019-06-03", 
"104 - 2019-06-03", "111 - 2019-05-31", "111 - 2019-05-31"), 
    Time = c("11:17:01", "12:48:51", "13:54:09", "14:14:46", 
    "14:19:46", "14:32:46", "14:19:27", "14:35:12", "15:30:22", 
    "15:31:22", "16:29:12", "09:31:53", "09:31:56"), Type = c("IN", 
    "Out", "IN", "IN", "IN", "IN", "Out", "Out", "IN", "IN", 
    "Out", "IN", "Out"), Category = c("Include", "Include", "Include", 
    "Exclude", "Exclude", "Exclude", "Exclude", "Include", "Include", 
    "Exclude", "Include", "Include", "Include")), row.names = c(NA, 
-13L), class = c("tbl_df", "tbl", "data.frame"))

Being a swipe data sorted based on time and ID, need to consider if the person is marked as "IN" and then "Out" makes it a one proper entry. I mark both the IN and OUT as "Include" if it happens sequentially. Sometime, there are multiple consecutive IN and OUT entry and in those cases I mark the First "IN" as include and the "last "OUT" as include. The in between entries are marked as exclude. Thanks!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>