MY DATA
Fruits <- c("Orange","Orange","Pineapple","Pineapple","Orange","Orange","Blueberry")
Location <- c(10, 11, 15, 16, 10, 11, 30)
MY PROBLEM
I wish to add a new column, Entry
that contains a different ID for when there is a change in Fruit
from the row above.
EXAMPLE OF WHAT I WOULD LIKE
Fruits <- c("Orange","Orange","Pineapple","Pineapple","Orange","Orange","Blueberry")
Location <- c(10, 11, 15, 16, 10, 11, 30)
Entry <- c(1, 1, 2, 2, 3, 3, 4)
Note how the second entry of "Orange"
receives a different ID to the first, even though it is added at the same Location
. My thought is to write a loop that would iterate over Fruits
for a change in text, placing a value in Entry
. All values in Entry
must be consecutive. This seems a simple exercise but I am stuck!
Thank you.