Here's another interesting problem: if you recall I have a data frame (LCvars1) that consists of about 1500 cases (rows) of data from kids who took a test of listening comprehension. The columns are their scores (1 = correct, 0 = incorrect,  . = missing) on 140 test items. The items are numbered sequentially and are ordered by increasing difficulty as you go from left to right across the columns.

I used the following (thanks to Peter Ehlers for this solution):

First1ItemNo <- as.vector(
  apply(
  LCvars1, 1, match, x=1
  ))

to make R go through the columns from left to right and record into a vector the column number of the first '1' response for each case.

Now, for each case (row), I want R to START with the column that contains the first '1' response, and continue to the right and count the number of consecutive columns containing '1' responses. At the next '0' or '.', I want R to record the count of consecutive '1's, and the skip to the next row and begin the process anew.

Thanks in advance for your help,

David S. Herzberg, Ph.D.
Vice President, Research and Development
Western Psychological Services
12031 Wilshire Blvd.
Los Angeles, CA 90025-1251
Phone: (310)478-2061 x144
FAX: (310)478-7838
email: davidh@wpspublish.com<mailto:davidh@wpspublish.com>



	[[alternative HTML version deleted]]

