R - I have 3 variables with data below. Variable "Rev" is a vector that changes from 1 to 2, 2 to 3, etc.... Variable "FF" is a binary variable with 1's and 0's. Variable "bin" is a different binary variable with 1's and 0's.
I want to calculate the number of elements: 1. Starting with the first element where Rev switches (i.e. 1 to 2) 2. The number of elements between the transition and the first 0 in the "FF" vector; *when "bin" is also a 0.* * * 3. I want to do this for each transition in Rev, but ignore all elements after calculating #2 until another transition has occurred. structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c("Rev", "FF", "bin" ), row.names = c(NA, -40L), class = "data.frame") -- Edward H. Patzelt Research Assistant TRiCAM Lab University of Minnesota Psychology/Psychiatry VA Medical Center Office: S355 Elliot Hall - Twin Cities Campus Phone: 612-626-0072 Email: patze...@umn.edu Please consider the environment before printing this email www.psych.umn.edu/research/tricam [[alternative HTML version deleted]]
______________________________________________ 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.