Reputation: 39
My data is organized as eg:
x country
1 FR
1 FR
1 NO
2 UK
3 ES
3 ES
4 NO
So I have repetitions of the same x and country for several rows, and sometimes while x is the same the country changes
How can I merge rows if the country and x are repeatedly the same for several rows, while taking into account that in some cases the country is different for the same x?
Upvotes: 0
Views: 590
Reputation: 102700
If I understand your goal correctly, maybe you need to use unique
> unique(df)
x country
1 1 FR
3 1 NO
4 2 UK
5 3 ES
7 4 NO
Data
> dput(df)
structure(list(x = c(1L, 1L, 1L, 2L, 3L, 3L, 4L), country = c("FR",
"FR", "NO", "UK", "ES", "ES", "NO")), class = "data.frame", row.names = c(NA,
-7L))
Upvotes: 2