I have two columns in a data frame. Based on the unique ids in column 1, I want to create a new column that has all the values from column 2 corresponding to that unique id in column1 separated by ,.
for example:
col1<-c("x", "y", "x", "z", "x", "z")
col2<-c("NY","UT","CA","SA", "SW", "GR")
col3<-c(1, 5, 7, 4, 7, 2)
df<-data.frame(col1, col2, col3, stringsAsFactors=FALSE)
and I want
col1<-c("x", "y", "z")
col2<-c("NY CA SW", "UT","SA, GR")
df2<-data.frame(col1, col2, stringsAsFactors=FALSE)