[R] same key row merge in dataframe
arun
smartpink111 at yahoo.com
Thu May 9 13:31:26 CEST 2013
HI,
Try this:
dat1<- read.table(text="
V1 V2
A 1
B 2
A 1
B 3
",sep="",header=TRUE,stringsAsFactors=FALSE)
library(plyr)
ddply(dat1,.(V1),summarize, V2=list(V2))
# V1 V2
#1 A 1, 1
#2 B 2, 3
#or
aggregate(V2~V1,data=dat1,FUN= function(x) x,simplify=FALSE)
# V1 V2
#1 A 1, 1
#2 B 2, 3
A.K.
>Dear R-users,
>
>I have dataframe
>V1 V2
>A 1
>B 2
>A 1
>B 3
>
>I want to get this output
>
>V1 V2
>A 1,1
>B 2 ,3
>
>
>How to.... ??
>
>Please
More information about the R-help
mailing list