I have a very specific question about data cleaning in R and am not sure how should I achieve this. Basically, you can find below an example data frame.
test <- data.frame(personID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
sequenceTrip = c(1, 1, 2, 2, 3, 3, 4, 4), departureHour = c(9L,
9L, 13L, 13L, 14L, 14L, 16L, 16L), departureMinute = c(34L,
34L, 34L, 34L, 35L, 35L, 19L, 19L), tripRangeTypeOrigin = c(0,
0, 1, 1, 0, 0, 1, 1), arrivalHour = c(10, 10, 14, 14, 15,
15, 18, 18), arrivalMinute = c(34, 34, 34, 34, 49, 49, 4,
4), tripRangeTypeDestin = c(1, 1, 0, 0, 1, 1, 0, 0), tripPurpose = c("leisure",
"leisure", "return home", "return home", "shopping", "shopping",
"return home", "return home"), mode = c("car", "car", "car",
"car", "car", "car", "car", "car"), tripDistance = c(77,
77, 77, 77, 100, 100, 115, 115), typicalDurationNextActivity = c(10800,
10800, 60, 60, 1800, 1800, 24960, 24960), arrivalTimeInMInute = c(NA,
NA, NA, NA, NA, NA, 1084, 1084), originDestinType = c(0,
1, 0, 1, 0, 1, 0, 1), tripNB = c("MUTSAARD", "Outside Brussels",
"Outside Brussels", "HEYSEL", "HEYSEL", "Outside Brussels",
"Outside Brussels", "CHAUSSEE DE WAVRE - SAINT-JULIEN "))
What I want to achieve is keeping the 1st, 2nd, second last (row 7 in this case) and last (row 8 in this case) rows of this dataframe, meanwhile, for rows 3:6, I want to filter out the rows which originDestinType == 1. So the final data frame would be 6 rows in total. I know this can be achieved by command like rbind, however, I am wondering if there is an easier way for achieving this using package like dplyr?
Thanks very much for your help!