STV (version 1.0.1)

cleanBallots: Tries to Address validateBallots() Warning(s).

Description

The cleanBallots() function tries to clean data for use in stv(). Some warnings from validateBallots() can only be addressed by the user.

Usage

cleanBallots(x, cand.names = NULL)

Arguments

x

a data.frame with rows as ballots and columns as candidates.

cand.names

character vector of length equal to number of candidates (needed when column names of x are missing or not unique).

Value

a data.frame compatible for stv() function.

Details

The cleanBallots() function assumes x contains rows and columns corresponding to ballots and candidates respectively. Formatting corrections are attempted in the following order:

  1. If x is a matrix it is convered to a data.frame. Otherwise, user must provide a data.frame.

  2. If x has non-numeric entries, user must convert data to numeric type.

  3. If cand.names is specified, it is assigned as column names of x. All collumn names must be uniquely specified. x already has valid column names, no need to specify cand.names. If column names of x missing and cand.names not specified, returns error message.

  4. Removes blank columns.

  5. Removes blank and/or non-sequentially ranked rows.

Examples

Run this code
# NOT RUN {
data(ballots)
cballots <- cleanBallots(ballots)
validateBallots(cballots)
# }

Run the code above in your browser using DataLab