[R] filter seq wise

arun smartpink111 at yahoo.com
Fri Mar 14 15:47:45 CET 2014


Hi,
Please use ?dput() to show the data.

dat <- read.table(text="id name seq
 101 as 1
 102 ld 2
 103 eg 3
 101 as 4
 104 bs 5
 103 eg 6
 105 ka 7
 104 bs 8",sep="",header=TRUE,stringsAsFactors=FALSE)
res1 <- aggregate(seq~.,data=dat,FUN=I)
 res1 <- res1[order(res1$id),] ##creates the column 'seq' as a list
#or
res2 <- aggregate(seq~.,data=dat,FUN=paste,collapse=",")
res2 <- res2[order(res2$id),] #seq as character column

#or
library(plyr)
 res3 <- ddply(dat,.(id,name),summarise,seq=paste(seq,collapse=","))
A.K.


hi, users solve this one
id name seq 
101 as 1 
102 ld 2 
103 eg 3 
101 as 4 
104 bs 5 
103 eg 6 
105 ka 7 
104 bs 8 
finaly output is 
id name seq 
101 as 1,4 
102 ld 2 
103 eg 3,6 
104 bs 5,8 
105 ka 7 
solve pls......................



More information about the R-help mailing list