On Fri, 11 Jul 2014 12:19:39 PM Ryan de Vera wrote:
> Hello all,
> 
> I have a data frame filled with senders and recipients. Some of the 
senders
> have multiple rows with different recipients and I want to merge 
those
> rows. For example I have
> 
> [email protected]     [email protected]
> [email protected]     [email protected]     [email protected]
> [email protected]      [email protected]
> [email protected]      [email protected]
> 
> I want this to become
> 
> [email protected]     [email protected]     [email protected]     [email protected]
> [email protected]      [email protected]      [email protected]
> 
> How would I go about doing this?
> 
Hi Ryan,
This is a bit messy, but assuming that you do have a data frame like 
this:

rdvdf<-
data.frame(sender=rep(c("[email protected]","[email protected]"),each=2),
 
recipient1=c("[email protected]","[email protected]","[email protected]","[email protected]"),
 recipient2=c(NA,"[email protected]",NA,NA))

you can try this:

newdat<-list()
senderno<-1
for(sndr in unique(rdvdf$sender)) {
 newvec<-
  as.character(unique(unlist(rdvdf[rdvdf$sender==sndr,])))
 newdat[[senderno]]<-newvec[!is.na(newvec)]
 senderno<-senderno+1
}

Jim

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to