Re: [R] define subgroups based on position in table

2010-07-20 Thread jim holtman
try this: > x <- read.table(textConnection("group + A + A + A + B + B + A + A + B + B + B + A + A"),header=TRUE, as.is=TRUE) > closeAllConnections() > # use rle to get the 'runs' > x.rle <- rle(x$group) > # now generate the group numbers > x.grp <- ave(x.rle$values, x.rle$values, FUN=seq_along) >

[R] define subgroups based on position in table

2010-07-20 Thread STEVENS, Maarten
Dear list, I have a data frame with one column (group) and want to add a second column (sub) with a serial number that says to which subgroup a cell belongs. A subgroup contains the consecutive rows of the same group. The number of a subgroup is based on its position in the table. The first su