Germán Bonilla
2009-Jun-17 22:24 UTC
[R] function to determine to which class/category a value belongs to?
Hi all, I''ve got a simple contingency table produced with table(), and the upper and lower quartiles (quantile25 and quantile75) for the same dataset. Is there a function that tells me in which category does the value of the quartile falls into? for example: tabsp <- table(fam$I[fam$I>0]) 1 3 6 6 1 1 and for the cumulative frequency distribution tabcum <- cumsum(tabsp) 1 3 6 6 7 8 so, If my lower quartile is "2", I can visually determine that it falls into class/category "1" with 6 observations. Is there a function that performs this determination? Thanks. Germán Bonilla I. Ecol. UNAM [[alternative HTML version deleted]]
David Winsemius
2009-Jun-17 23:30 UTC
[R] function to determine to which class/category a value belongs to?
You might want to experiment with:
ql <- cut( fam$I[fam$I>0], breaks = quantile( fam$I[fam$I>0],
type=1) , right=FALSE)
levels(ql) <-
c("1stQ","2ndQ","3rdQ","4thQ")
ql
cut() returns a factor. If you accept the default for the right
parameter in cut, you will be pulling your hair out when dealig with a
discrete variable.
On Jun 17, 2009, at 6:24 PM, Germ?n Bonilla wrote:
> Hi all,
>
> I've got a simple contingency table produced with table(), and the
> upper and
> lower quartiles (quantile25 and quantile75) for the same dataset.
> Is there a function that tells me in which category does the value
> of the
> quartile falls into?
I cannot quite parse this sentence. See if the example gives a
meaningful result with your data, and read the help pages for quantile.
>
> for example:
>
> tabsp <- table(fam$I[fam$I>0])
>
> 1 3 6
> 6 1 1
>
> and for the cumulative frequency distribution
>
> tabcum <- cumsum(tabsp)
>
> 1 3 6
> 6 7 8
>
> so, If my lower quartile is "2", I can visually determine that it
> falls into
> class/category "1" with 6 observations. Is there a function that
> performs
> this determination?
>
> Thanks.
>
> Germ?n Bonilla
> I. Ecol. UNAM
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT