r - Create numbered sequence for occurrences of a given nesting variable -
I'm hoping to add data to a variable that sets a variable group variable. For example:
id & lt; - c (Representative (1,4), Representative (2,6), Representative (3,2))
I want another variable which calculates the examples which appear on each ID Will do Creating vector like this:
1,2,3,4,1,2,3,4,5,6,1,2
Some of them are looking like this:
ID count 1 1 2 1 2 3 1 3 4 1 4 5 2 1 6 2 2 7 2 3 8 2 4 9 2 5 10 2 6 11 3 1 12 3 2
Any thoughts? thanks a lot!
I suggest that with ave
seq_along
id & lt; - c (Representative (1,4), Representative (2,6), Representative (3,2)) Count & lt; - Away (id, id, fune = (id, count) #IID number # [1,] 1 1 # [2,] 1 2 # [3,] 1 3 # [4,] 1 4 # [5,] 2 1 # [6,] 2 2 # [7,] 2 3 # [8,] 2 4 # [9,] 2 5 # [10,] 2 6 # [11,] 3 1 # [12,] 3 2
Comments
Post a Comment