Sha256: 9c67b9665bef3972d66d9d8dd6abf1896df50b18ee288fee881ee586c88aeb6c

Contents?: true

Size: 1.07 KB

Versions: 219

Compression:

Stored size: 1.07 KB

Contents

tournament <- function(input) {

  results <- data.frame(Team = "tempTeam", MP = 0, W = 0, D = 0, L = 0, P = 0)
  
  for (item in input) {
    
    match <- unlist(strsplit(item, ";"))
    # Check that match result is valid
    if (length(match) != 3 || !(match[3] %in% c("draw", "win", "loss"))) {
      next
    }
    else {
      # Process result
      if (match[3] == "draw") {
        results <- rbind(results, 
                         c(match[1], 1, 0, 1, 0, 1), 
                         c(match[2], 1, 0, 1, 0, 1))
      } else if (match[3] == "win") {
        results <- rbind(results, 
                         c(match[1], 1, 1, 0, 0, 3), 
                         c(match[2], 1, 0, 0, 1, 0))
      } else {
        results <- rbind(results, 
                         c(match[2], 1, 1, 0, 0, 3), 
                         c(match[1], 1, 0, 0, 1, 0))
      }
    }
    
  }
  
  results[, 2:6] <- sapply(results[, 2:6], as.numeric)
  
  output <- aggregate(.~Team, results[-1, ], sum)
  output <- output[order(-output$P, output$Team), ]
  row.names(output) <- 1:nrow(output)
  output
  
}

Version data entries

219 entries across 219 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/r/exercises/tournament/example.R
trackler-2.2.1.118 tracks/r/exercises/tournament/example.R
trackler-2.2.1.117 tracks/r/exercises/tournament/example.R
trackler-2.2.1.116 tracks/r/exercises/tournament/example.R
trackler-2.2.1.115 tracks/r/exercises/tournament/example.R
trackler-2.2.1.114 tracks/r/exercises/tournament/example.R
trackler-2.2.1.113 tracks/r/exercises/tournament/example.R
trackler-2.2.1.111 tracks/r/exercises/tournament/example.R
trackler-2.2.1.110 tracks/r/exercises/tournament/example.R
trackler-2.2.1.109 tracks/r/exercises/tournament/example.R
trackler-2.2.1.108 tracks/r/exercises/tournament/example.R
trackler-2.2.1.107 tracks/r/exercises/tournament/example.R
trackler-2.2.1.106 tracks/r/exercises/tournament/example.R
trackler-2.2.1.105 tracks/r/exercises/tournament/example.R
trackler-2.2.1.104 tracks/r/exercises/tournament/example.R
trackler-2.2.1.103 tracks/r/exercises/tournament/example.R
trackler-2.2.1.102 tracks/r/exercises/tournament/example.R
trackler-2.2.1.101 tracks/r/exercises/tournament/example.R
trackler-2.2.1.100 tracks/r/exercises/tournament/example.R
trackler-2.2.1.99 tracks/r/exercises/tournament/example.R