[R] Adding rows based on column value
Bansal, Vikas
vikas.bansal at kcl.ac.uk
Thu Jul 14 17:35:35 CEST 2011
Dear all,
I have one problem and did not find any solution.(I have also attached the problem in text file because sometimes column spacing is not good in mail)
I have a file(file.txt) attached with this mail.I am reading it using this code to make a data frame (file)-
file=read.table("file.txt",fill=T,colClasses = "character",header=T)
file looks like this-
Chr Pos CaseA CaseC CaseG CaseT
10 135344110 0.000000 24.000000 0.000000 0.000000
10 135344110 0.000000 0.000000 24.000000 0.000000
10 135344110 0.000000 0.000000 24.000000 0.000000
10 135344113 0.000000 0.000000 24.000000 0.000000
10 135344114 24.000000 0.000000 0.000000 0.000000
10 135344114 24.000000 0.000000 0.000000 0.000000
10 135344116 0.000000 0.000000 0.000000 24.000000
10 135344118 0.000000 24.000000 0.000000 0.000000
10 135344118 0.000000 0.000000 0.000000 24.000000
10 135344122 24.000000 0.000000 0.000000 0.000000
10 135344122 0.000000 24.000000 0.000000 0.000000
10 135344123 0.000000 24.000000 0.000000 0.000000
10 135344123 0.000000 24.000000 0.000000 0.000000
10 135344123 0.000000 0.000000 0.000000 24.000000
10 135344126 0.000000 0.000000 24.000000 0.000000
Now some of the values in column Pos are same.for these same positions i want to add the values of columns 2:6
I will explain with an example-
The output of first row should be-
Chr Pos CaseA CaseC CaseG CaseT
10 135344110 0.000000 24.000000 48.000000 0.000000
so the whole output for above input should be-
Chr Pos CaseA CaseC CaseG CaseT
10 135344110 0.000000 24.000000 48.000000 0.000000
10 135344113 0.000000 0.000000 24.000000 0.000000
10 135344114 48.000000 0.000000 0.000000 0.000000
10 135344116 0.000000 0.000000 0.000000 24.000000
10 135344118 0.000000 24.000000 0.000000 24.000000
10 135344122 24.000000 24.000000 0.000000 0.000000
10 135344123 0.000000 48.000000 0.000000 24.000000
10 135344126 0.000000 0.000000 24.000000 0.000000
Can you please help me.
Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: file.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110714/d0532f56/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: question.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110714/d0532f56/attachment-0001.txt>
More information about the R-help
mailing list