Skip to content
Prev 276350 / 398506 Next

how to count number of occurrences

You should really provide the relevant context from previous posts so that potential helpers don't need to go looking for it.  That being said, you could try something like

samp <- c("X", "Y", "X", "X", "X", "X", "Y", "Y", "Y", "Y", "X", "X", "X", "X", "X", "Y", "Y", "Y", "Y", "Y")
diff(which(c('Y', samp)=='Y'))-1 


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204