list2ballot {votesys} | R Documentation |
Repeat ith element of list x or row of matrix/data.frames for j times
Description
Suppose you have 3 different unique ballots and the amount of each ballot is 10, 20, 30. Now you want to create raw ballots as a list. Then you can use this function. See examples for usage.
Usage
list2ballot(x = NULL, n = rep(1, length(x)), m = NULL, string = NULL)
Arguments
x |
a list, each element of which should be a vector. Note:
only one of |
n |
how many times each element of |
m |
a matrix or dataframe, the number of rows should be equal to the length of n. |
string |
default is NULL. If it is not NULL, |
Value
a list with replicated vectors, if x
is not NULL,
or a matrix/data.frame with duplicated rows, if
m
is not NULL.
Examples
# Use x and n
unique_ballot <- list(
c("A", "B", "C"), c("F", "A", "B"),
c("E", "D", "C", "B", "F", "A"), c("x","x", "A")
)
r <- c(1, 2, 3, 0)
y <- list2ballot(unique_ballot, r)
# Use string, x and n will be ignored.
# The characters can be written in a very loose way as follows,
# for the function will automatically delete unwanted parts.
# But do make sure there is no space or punctuation
# inside the names.
unique_ballot <- c(
"2, Bob, Mike Jane", "3: barack_obama;;Bob>Jane",
"0 Smith Jane", " 1 Mike???!!!"
)
y <- list2ballot(string = unique_ballot)
# Use a matrix.
m <- matrix(c(1, 2, 3, 3, 1, 2), nrow = 2, byrow = TRUE)
colnames(m) <- c("p1", "p2", "p3")
r <- c(3, 5)
y <- list2ballot(m = m, n = r)