Hi John.

This would have to be a data frame (not a matrix) as you could not have different data types in your matrix. Try the function aggregate, e.g.:

obj<-data.frame(number=c(1,1.5,0.2,0.8,1.0,3.2),
        tree=factor(c("A","A","B","C","A","B")))
obj ## data frame
aggregate(obj$number,by=list(obj$tree),sum)

- Liam

Liam J. Revell, Associate Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: [email protected]
blog: http://blog.phytools.org

On 5/30/2016 12:13 PM, John Denton wrote:
Hi all,

I have a two-column matrix, containing trees in one column and a numeric value 
associated with each tree in the other column. I would like to go through the 
list to identify any duplicated topologies, and for each set of duplicates sum 
the corresponding numeric values and prune away the duplicate trees.

For example,

1.0   A
1.5   A
0.2  B
0.8.  C
1.0.  A
3.2.  B

Would become

3.5.  A
3.4. B
0.8.  C

Any help would be great!

Thanks,

~John
_______________________________________________
R-sig-phylo mailing list - [email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/[email protected]/


_______________________________________________
R-sig-phylo mailing list - [email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/[email protected]/

Reply via email to