Skip to content
Advertisement

Concatenate values in a column by group within a loop (R or SQL)

Suppose I’ve got this data:

I want a list aggregation by key in R/SQL that would produce this last column:

The value in Class in the current row always includes current and future values within a group (key).

Any Suggestions?

Many thanks!

Advertisement

Answer

In R, you can group by key and create a sequence from id to the number of rows in the group and paste the value together.

data

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement