For completeness.

On Thu, May 6, 2010 at 8:03 PM, Joris Meys <jorism...@gmail.com> wrote:

> Table <- matrix(ncol=3,nrow=4,c(0,0,0,0,7,2,1,3,4,0,3,4))
>
> # one way
> t(t(Table)/colSums(Table))
>
> # another way
> apply(Table,2,function(x){x/sum(x)})
>
> Take in mind that your solution is wrong. If you divide 0 by 0, you get
> NaN. If you want this not to happen, you'll have to add an extra control.
>

> On Thu, May 6, 2010 at 7:06 PM, n.via...@libero.it <n.via...@libero.it>wrote:
>
>>
>> Dear list,
>> Im trying to do the following operation but im not able to do it
>> This is my table:
>>         1 2 3
>> 1      0 7 4
>> 2      0 2 0
>> 3      0 1 3
>> 4      0 3 4
>>
>> what i would like to do is
>>
>> divide each row values with the corresponding column' sum,namely:
>>
>>         1           2              3
>> 1      0           0.54       0.36
>> 2      0           0.15        0
>> 3      0           0.08       0.27
>> 4      0           0.23       0.36
>>
>>
>> thanks for your attention
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@r-project.org 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.
>>
>
>
>
> --
> Joris Meys
> Statistical Consultant
>
> Ghent University
> Faculty of Bioscience Engineering
> Department of Applied mathematics, biometrics and process control
>
> Coupure Links 653
> B-9000 Gent
>
> tel : +32 9 264 59 87
> joris.m...@ugent.be
> -------------------------------
> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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