[R] id number by group and correlative

Sebastián Daza sebastian.daza at gmail.com
Wed Feb 16 16:00:53 CET 2011


Hello everyone,
I am new in R and I am trying to create a id number (a correlative 
sequence of numbers) by group, and a correlative sequence of numbers 
inside each group (my idea is to get statistics by group  without having 
to aggregate the database). Here an example:

group	id_group	correlative_group
A		1		1
A		1		2
A		1		3
A		1		4
B		2		1
B		2		2
B		2		3
C		3		1
C		3		2
C		3		3
C		3		4
C		3		5

Unfortunately, I have been able to find an explicit lag function to get 
id_group (I know I can get it using aggregate and merge but I'm just 
wondering if there is another way to do it). With regard to the 
correlative_group, I don't have any clue about how to do it.

PD: Last question. Is there any way to save in a variable the internal 
that R uses (those numbers that appear on left side of a dataframe)?

Thank you,
Sebastian.
-- 
Sebastián Daza
sebastian.daza at gmail.com



More information about the R-help mailing list