Hi,
I am having some problems setting up some indicators and would appreciate any
help.
I have some data called 'lights' with 3 variables called x, a and b.
x - is the date
a - equals 1 to indicate an 'on' button is activated
b - equals 1 to indicate an 'off' button is activated
Essentially i wannt to create 2 new variables c and d
c - will reflect the current state of the light (1 being on)
d - will be a count for how many days the light has been on
here's some data with the date omitted to illustrate what i have and what is
required.
a b c d
0 0 0 0
0 0 0 0
1 0 1 1
1 0 1 2
0 0 1 3
0 0 1 4
1 0 1 5
0 0 1 6
0 0 1 7
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1 0 1 1
0 0 1 2
0 0 1 3
0 0 1 4
0 1 0 0
0 0 0 0
After some considerable time i have managed to create variable c with a loop
but it's really slow with the volume of data i have. Could anyone please show
me how to do this efficiently?
I hope this is clear...
Thanks
Roy
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.