weighted.table: Calculate the weighted table of discrete attribute value...

Description Usage Arguments Details Value Author(s) Examples

View source: R/r-utility-weighted-table.R

Description

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.

Usage

1
weighted.table(v, ..., w=rep(1, length(v)), dnn=NULL)

Arguments

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

Details

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.

Value

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.

Author(s)

Pawel Cichosz <p.cichosz@elka.pw.edu.pl>

Examples

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))

42n4/dmr.util documentation built on May 20, 2019, 2:02 p.m.