Description Usage Arguments Details Value Author(s) Examples
View source: R/r-utility-weighted-table.R
This function generates a weighted frequency table for one or more value vectors and a given weight vector. It is used in examples presented in the book Cichosz, P. (2015): Data Mining Algorithms: Explained Using R. See Appendix B or http://www.wiley.com/go/data_mining_algorithms for more details.
1 | weighted.table(v, ..., w=rep(1, length(v)), dnn=NULL)
|
v |
an input vector |
... |
possibly additional input vectors of the same length |
w |
a weights vector of the same length |
dnn |
a vector of dimension names for the output table |
This function is a simple weighted counterpart of the
table
function. For each combination of input vector values it
calculates the weighted occurrence count by summing up the corresponding
weights. If weights are all equal 1
, these are the same as the
ordinary occurrence counts returned by table
.
An object of the table
class containing weighted
occurrence counts for all value combinations observed on input, i.e.,
for each input value combination, the sum of weights corresponding to
all observations for which it occurs.
Pawel Cichosz <p.cichosz@elka.pw.edu.pl>
1 2 3 4 5 | data(weather, package="dmr.data")
weighted.table(weather$play)
weighted.table(weather$play, w=ifelse(weather$play=='yes', 2, 1))
weighted.table(weather$outlook, weather$play, dnn=c("outlook", "play"))
weighted.table(weather$outlook, weather$play, w=ifelse(weather$play=='yes', 2, 1))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.