Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

r - long to wide format, but without condition


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...