#' @title Generate a Random Single Voting Network for the 2014 ESC Final
#'
#' @description Generate a Random Single Voting Network for the 2014 ESC Final
#'
#' @return Outputs a list of objects related to a single Random 2014 ESC Final Voting Network as an igraph Object.
#'
#' @import igraph
#'
#' @export
#'
#' @seealso
#'
#' @keywords Random Network, 2014 ESC Final
#'
#' @references
#'
#' @examples
#' # Example Data
#' rand_graph = random_single_level()
#'
random_single_level = function(){
randSL = list()
# Algorithmic appraoch
# STEP 1: create Country_From Column
# NOTE assume 1:26 are the performing countries and 27:37 are the non-performing countries
Country_From <- seq(from = 1, to = 37, by = 1)
# Step 2: create Country_To Column
# random votes for performers
# NOTE performers cannot vote for themselves
performer_votes <- numeric(0)
for(i in 1:26) {
v <- sample(x = c(1:26)[-i], size = 1, replace = F)
performer_votes <- c(performer_votes, v)
}
# random votes for non-performers
non_performer_votes <- sample(x = 1:26, size = 11, replace = F)
# combine the votes for both performers and non performers
Country_To <- c(performer_votes, non_performer_votes)
# Step 3: Create a Data Frame from Country_From and Country_TO
RG_DF <- cbind(Country_From, Country_To)
# add the RG_DF to the list
randSL[[1]] = RG_DF
# Step 4: Create the Random Graph using the Data Frame
RG <- graph_from_data_frame(d = RG_DF, directed = T)
# add the RG_DF to the list
randSL[[2]] = RG
# Step 5: Calculate degree distibution for random graph
RG_degree_dist <- degree_distribution(graph = RG, mode = "in")
# add the RG_degree_dist to te randSL
randSL[[3]] = RG_degree_dist
# return the randSL
return(randSL)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.