Here is an option with aggregate
from base R
aggregate(City ~ ID, df1, toString)
-output
# ID City
#1 x Paris, Madrid
#2 y Paris, Prague, Moscow
#3 z Moscow
data
df1 <- structure(list(ID = c("x", "x", "y", "y", "y", "z"), City = c("Paris",
"Madrid", "Paris", "Prague", "Moscow", "Moscow")), class = "data.frame",
row.names = c(NA,
-6L))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…