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 subgroup of A's and B's should have nr A1 and B1, the second nr A2 and B2, etc.. I hope the example below makes things more clear. This is what my data look like: x <- read.table(textConnection("group A A A B B A A B B B A A"),header=TRUE) closeAllConnections() group 1 A 2 A 3 A 4 B 5 B 6 A 7 A 8 B 9 B 10 B 11 A 12 A This is what it should become: group sub 1 A A1 2 A A1 3 A A1 4 B B1 5 B B1 6 A A2 7 A A2 8 B B2 9 B B2 10 B B2 11 A A3 12 A A3
Maarten Stevens Senior onderzoeker - Aquatisch Beheer / Senior scientist - Aquatic Management INBO Instituut voor Natuur- en Bosonderzoek / Research Institute for Nature and Forest Afdeling Beheer en Duurzaam Gebruik / Dept. Management and Sustainable Use Kliniekstraat 25 B-1070 Brussels, BELGIUM E-mail: maarten.stev...@inbo.be <mailto:maarten.stev...@inbo.be> Phone: +32.2.558.19.18 Gsm / Cell: +32.492.72.28.97 Fax: +32.2.558.18.05 www.inbo.be <http://www.inbo.be/> Druk dit bericht a.u.b. niet onnodig af. Please do not print this message unnecessarily. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. [[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.