#' Calculating the Rice Index
#'
#' This function allows you to easily calculate the Rice Index for a given vote.
#' @param temp_freq A vector containing the number of votes for yes and no in any given order. If a vector of length 1 is given, it is assumed that all votes were casted for the same option.
#' @keywords rollcall
#' @export
#' @examples
#' rice_index()
#'
#' test_rice <- c(15,2)
#'test_rice_shorter <- c(15)
#'test_rice_longer <- c(15,2,5)
#'
#'rice_index(test_rice)
#'rice_index(test_rice_shorter)
#'rice_index(test_rice_longer)
rice_index <- function(temp_freq) {
ifelse( length(temp_freq)<3,
ifelse(length(temp_freq)==1, 1, RiceScore <- abs(max(temp_freq)-min(temp_freq))/sum(temp_freq)),
stop("Vector of No./Share of Yes and No Votes longer than two."))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.