[R] List of occuring values
William Dunlap
wdunlap at tibco.com
Thu Sep 21 16:38:32 CEST 2017
unique(x) will give you the distinct values in x. table(x) will give you
the distrinct values and their frequencies as an array with dimnames.
data.frame(table(x)) will give you a 2-column data.frame with the distinct
values and their frequencies.
> values <- c("Small", "Large", "Large", "Large")
> unique(values)
[1] "Small" "Large"
> tblValues <- table(values)
> tblValues
values
Large Small
3 1
> tblValues[tblValues > 2, drop=FALSE]
values
Large
3
>
> dfValues <- data.frame(tblValues)
> dfValues
values Freq
1 Large 3
2 Small 1
> subset(dfValues, Freq > 2)
values Freq
1 Large 3
>
> factorValues <- factor(values,
levels=c("Small","Medium","Large","XLarge"))
> data.frame(table(factorValues))
factorValues Freq
1 Small 1
2 Medium 0
3 Large 3
4 XLarge 0
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Thu, Sep 21, 2017 at 6:01 AM, Ferri Leberl <ferri.leberl at gmx.at> wrote:
>
> Dear all,
> ftable produces a list of the frequencies of all occuring values.
> But how about the occuring values?
> How can I retrieve a list of occuring values?
> How can I retrieve a table with both the list of occuring values and their
> respective frequencies?
> Thank you in advance,
> Yours, Ferri
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list