I have two variables that represent the wake-up time and go to sleep time in minutes (example: If Person A went to bed at 00:40 it would be "40" for sleep_min).
id day wake_min sleep_min
1 ADD15 1 518 40
2 ADD15 2 540 45
3 ADD15 3 570 80
4 ADD15 4 487 50
5 ADD15 5 582 73
6 AHK1 1 405 1435
7 AHK1 2 611 1402
Then I have a second data set that has a row for each day and minute for every person. So Person ADD15 has 1440 rows for day 1, 1440 for day 2 etc.
id day minute
1: ADD15 1 1
2: ADD15 1 2
3: ADD15 1 3
4: ADD15 1 4
5: ADD15 1 5
6: ADD15 1 6
...
I want to create a new variable named "state" for the second data set. This one should represent if a person is whether sleeping or awake. The variable should be coded 1 for sleeping and 0 for being awake. In the case of day 1 of person ADD15, all rows for the minutes between 40 and 518 should have the value "1" and the other rows for day 1 "0".
I tried some things with teh ifelse function but nothing worked so far.
I would really appreciate some help and advices for my problem!
Thanks in advance!!