[R] adding counter to df by group

Davide Piffer
2017-05-04T07:17:50Z

Thanks David! I tried this but didn't work. Got a bunch of warning
messages: Warning messages:
1: In `[<-.factor`(`*tmp*`, i, value = 1:52) :

On 4 May 2017 at 02:23, David Winsemius <dwinsemius at comcast.net>
wrote:
>
>> On May 3, 2017, at 11:24 AM, Davide Piffer <pifferdavide at
gmail.com> wrote:
>>
>
> You should look at this result more closely. Its length is not the same
length as the number of rows of the target of the attempted assignment.
>
>> unlist(miniblock_cong)
>
> You might try:
>
> red_congruent$miniblock <- ave( red_congruent$subject_nr,
red_congruent$subject_nr, FUN=seq_along)
>
> `ave` is very useful for delivering vectors with length equal to nrow of a
dataframe. Do remember to name the FUN parameter (although I still usually
forget).
>
> --
>
> David Winsemius
> Alameda, CA, USA
>