I would like to return the position of an variable from a data frame. The data with has a serial (identification number), Day1 (week days from Mon.- Sun) that records the starting day of an observation and 7 variables day1 to day7 each representing a day of the week. Day1 is Mon and Day7 is Sun.
There is another WkDay2 variable that is used to record the position of an observation during the week.
I would like to identify the position of any observation. The starting day is recorded in WkDay1. For example in the case of id 12 the observation started on Monday and a new observation was recorded on Wednesday - on the Third day. In the case of id 123 the observation stared on Tuesday and a new observation was recorded on the same day - or first day. Finally, id 10, observation was made on Thursday and a new on the 4th day (after WDay1) or Sunday.
Input:
serial day1 day2 day3 day4 day5 day6 day7 WkDay1 WkDay2
12 2 1 2 1 1 3 1 Monday Wednesday
123 0 3 0 3 3 0 3 Tuesday Tuesday
10 0 3 3 3 3 3 3 Thursday Sunday
Output:
serial Position
12 Third
123 First
10 Fourth