[R] Query about using rowSums/ColSums on table results
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Apr 30 18:49:06 CEST 2007
Try
prop.table(tab, 1)
prop.table(tab, 2)
prop.table(tab)
for the three ways of taking fractions or see ?CrossTable in the
gmodels package.
On 4/30/07, lalitha viswanath <lalithaviswanath at yahoo.com> wrote:
> Hi
> I have data of the form
> class age
> A 0.5
> B 0.4
> A 0.56666
> C 0.785
> D 0.535
> A 0.005
> C 0.015
> D 0.205
> A 0.605
>
> etc etc...
>
> I tabulated the above
> as
> tab <-table(data$class, cut(data$age, seq(0,0.6,0.02))
>
> I wish to view the results in individual bins as a
> percentage of the points in each bin.
> So I tried
> tab/colSums(tab)
>
> However that is yielding Inf as a return value in
> places where clearly the result should be a non-zero
> value.
>
> Is there an alternate way to get the results in each
> bin as percentages of the total points in that
> age-bin?
>
> Thanks
> Lalitha
>
> ______________________________________________
> 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