r - Paste values together based on a grouping variable -
i'm new @ r programing , im trying rearrange data frame. have column ids , column y string values. there's more 1 y per id multiple rows same id different y. want 1 row per id , y value concatenated in same cell in other column. there function ?
original data id y apple b pear c grape grape b apple c grape transformed data id y apple,grape b pear, apple c grape
you can use aggregate
here paste unique elements each id
together
ggregate(y ~ id, unique(dat), paste, collapse = ", ")
data
dat <- read.table(text="id y apple b pear c grape grape b apple c grape", header=t)
edit added collapse
argument re @pdb comment , changed unique
re @davidarenburg
Comments
Post a Comment