[R] How to manipulate this data?

arun smartpink111 at yahoo.com
Wed Dec 18 18:58:48 CET 2013


Hi,

Try:
dat1<- read.table(text="name Value
  abc BXR
  abc DHH
  abc DHK
  def DHK
  def DSL
  ghi DSL
  abc DSM
  def DSM
  ghi DSM
  def DSS
  ghi DSS
  ghi DST
  abc DIW
  abc DIL
  ghi DIL",sep="",header=TRUE,stringsAsFactors=FALSE) 


aggregate(name~Value,data=dat1,paste,collapse=" ")
#or
library(plyr)
 ddply(dat1,.(Value),summarize, name=lapply(list(Value),paste,collapse=" "))
A.K.


Hi, 

I want my output to be like this: 
 Value 
BXR 
abc 

 DHH abc 

 DHK abc def 
 DSL def ghi 
 DSM abc def ghi  DSS def ghi 
 DST ghi 

 DIW abc 

 DIL abc ghi 

My input dataset is this with colnames name and Value: 

 name Value  abc BXR  abc DHH  abc DHK  def DHK  def DSL  ghi DSL  abc DSM 
def DSM  ghi DSM  def DSS  ghi DSS  ghi DST  abc DIW  abc DIL  ghi DIL 




More information about the R-help mailing list