I have some data with dates and names and a task that I'd like to order and work out the order of tasks that people do and the flow of tasks from one another. So, very simply here is some sample data.
Name Date Food
Fred 01/01/2018 Peanuts
Jim 03/02/2018 Banana
Barney 02/02/2018 Rice
Fred 06/03/2018 Rice
Barry 12/02/2018 Peanuts
John 04/04/2018 Rice
Jim 03/03/2018 Rice
Fred 20/04/2018 Rice
Den 12/02/2018 Banana
Barney 04/05/2018 Banana
Jim 05/06/2018 Rice
John 06/07/2018 Peanuts
Jim 30/06/2018 Banana
Fred 05/05/2018 Rice
This gives me the dates at which each of the named persons ate the specified food. What I would like to know is for each person the full list of foods they've ate plus the order they did them in.
I've used the order function in R and used created a seq from 1 to nrow to get the ordering but I don't know how to get this for each individual.
My second step is that I'd like to create a table of flows and a count of the number of times each flow is recorded so, the end result would be a table like this.
Flow count
Peanuts to rice 1
Peanuts to banana 0
Peanuts to peanuts 0
Rice to peanuts 1
Rice to banana 2
Rice to rice 3
Banana to rice 1
Banana to peanuts 0
Banana to banana 0
Thanks
UPDATE:
As ever with these things, the more I get into something the more alterations I'd like to do with the data!
So, the answer provided below has given me the flow table I want - thanks for that. now what I'd like to do is be able to edit my original data frame to remove instances of flows that I'm not interested in, or don't want to analyse.
So, for example, how would I remove from the data frame all flows (regardless of person) that say move from Rice to Peanuts or from Bananas to Rice?