[R] Add-up duplicates and merge

Theis, Winfried Winfried.Theis at unilever.com
Mon Feb 26 12:36:59 CET 2007


Hello,

 for the first task change the names if they are character into a factor
and have a look at ?by 
For the merge you will need strsplit() on character vectors (so be
carefull to change the factor back to character) and merge() 

Regards,
Winfried 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Serguei Kaniovski
Sent: Monday, February 26, 2007 12:14 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Add-up duplicates and merge


Hello,

a have two matrices of data as below. I would like to add-up the
duplicate in terms of pair of names in rows, and then merge the values
in the second matrix to the pairs as two new variables x3 and x4.

Input

,x1,x2
jane.mike,31,43
jane.steve,32,2
jane.steve,5,3
jim.mike,76,5
jane.steve,4,4
mike.steve,54,7
mike.steve,5,7
jane.mike,7,8

and

,y
jane,0.3
jim,0.4
mike,0.1
carl,0.5
john,0.9
steve,0.4
dirk,0.2

Output:

,x1,x2,x3,x4
jane.mike,38,51,0.3,0.1
jane.steve,41,9,0.3,0.4
jim.mike,76,5,0.4,0.1
mike.steve,59,14,0.1,0.4

Any help appreciated,
Serguei
	[[alternative HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list