Hi!
I'm having difficulty with trying to find the last vehicle record and returning which camera it used.
This is NOT Homework as per community rules .
Here's a small sample of the data:
VehicleData <- tibble::tribble(
~Vehicle, ~Camera,
"KXXX XXX", "CAMERA 1",
"RXXX XXX", "CAMERA 2",
"GXXX XXX", "CAMERA 3",
"KXXX XXX", "CAMERA 2",
"GXXX XXX", "CAMERA 1"
)
What I would like to do, is for the Vehicle KXXX XXX on row 4, I would like the column next to it to return "CAMERA 1" as that was the last Camera it picked up on.
The second criteria I would also like, is if the result is "CAMERA 3", then I would like to return "No Previous Record".
So my output would be something like this. The reason the top three would return N/As, as It cannot find a previous camera location.
Result <- tibble::tribble(
~Vehicle, ~Camera, ~Result,
"KXXX XXX", "CAMERA 1", NA,
"RXXX XXX", "CAMERA 2", NA,
"GXXX XXX", "CAMERA 3", NA,
"KXXX XXX", "CAMERA 2", "CAMERA 1",
"GXXX XXX", "CAMERA 1", "No Previous Result"
)
Any help appreciated!