[BioC] sum the values with same ID
guest [guest]
guest at bioconductor.org
Thu Mar 6 22:43:52 CET 2014
Dear R user,
I have a matrix like:
ID group1 group2 group3
s1 0 2 3
s2 1 0 4
s1 3 4 1
s4 2 2 0
I would like to sum the values with same ID to have the matrix as below:
ID group1 group2 group3
s1 3 6 4
s2 1 0 4
s4 2 2 0
I checked aggregate() may help to complete this job, but unfortunately I have the error message when I do this.
> all.data <- read.csv("test.csv")
> aggregate(group1 ~ ID, data=all.data, FUN=sum)
Error in eval(expr, envir, enclos) : object 'ID' not found
Please help me to generate the sum for the matrix. It's been appreciated for any help.
Thanks a lot
-- output of sessionInfo():
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RColorBrewer_1.0-5 vegan_2.0-10 lattice_0.20-24 permute_0.8-0 Heatplus_2.6.0 gplots_2.12.1
loaded via a namespace (and not attached):
[1] bitops_1.0-6 caTools_1.16 gdata_2.13.2 grid_3.0.2 gtools_3.1.1 KernSmooth_2.23-10 tools_3.0.2
--
Sent via the guest posting facility at bioconductor.org.
More information about the Bioconductor
mailing list