TPD-InternationalFootballRe.../.Rhistory

506 lines
13 KiB
R
Raw Normal View History

2019-05-14 22:41:05 +02:00
shiny::runApp()
runApp()
# Load data
football_data <- read.csv("results.csv")
head(football_data)
football_data <- as_tibble(read.csv("results.csv"))
library(dplyr)
football_data <- as_tibble(read.csv("results.csv"))
football_data %>% select(2)
football_data %>% select("home_team")
football_data %>% select("home_team") %>% unique()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
shiny::runApp()
runApp(display.mode = "showcase")
runApp(display.mode = "showcase")
runApp()
get_matches_list <- function(home_team, away_team) {
matches <- football_data %>%
select(1:5) %>%
filter("home_team" == home_team
& "away_team" == away_team)
return(matches)
}
get_matches_list("Scotland", "England")
head(get_matches_list("Scotland", "England"))
test <- get_matches_list("Scotland", "England")
test <- get_matches_list("Poland", "England")
test
football_data %>% filter("home_team" == "England")
football_data %>% filter(1 == "England")
football_data %>% filter(2 == "England")
matches <- football_data %>%
select(1:5) %>%
filter("home_team" %in% c(first_team, second_team)
& "away_team" %>% c(first_team, second_team))
matches <- football_data %>%
select(1:5) %>%
filter("home_team" %in% c("England")
)
football_data %>% filter(str_detect("home_team", "England")
)
library(stringr)
football_data %>% filter(str_detect("home_team", "England")_
football_data %>% filter(str_detect("home_team", "England"))
football_data %>% filter(str_detect(2, "England"))
football_data %>% filter(home_team == "England")
runApp()
runApp()
football_data_ext <- football_data %>%
select(2:4)
head(football_data_ext)
football_data_ext <- football_data %>%
select(2:6)
head(football_data_ext)
head(football_data)
football_data["home_team"]
get_winner_name <- function(match_row) {
if(match_row["home_score"] > match_row["away_score"]) {
return(match_row["home_team"])
}
else if(match_row["home_score"] < match_row["away_score"]) {
return(match_row["away_team"])
}
else {
return("Draw")
}
}
get_winner_name(football_data[0])
head(football_data)
get_winner_name(football_data[1])
football_data[1]
football_data[, 1]
top_n(football_data, 1)
football_data %>% slice(1)
football_data %>% slice(1) %>% get_winner_name()
football_data %>% select(2:5) %>% get_winner_name()
football_data %>% select(2:5)
football_data %>% select(2:5) %>% mutate(get_winner_name())
football_data %>% select(2:5) %>% mutate(get_winner_name(.))
football_data %>% select(2:5) %>% mutate(result = get_winner_name(.))
football_data %>% select(2:5) %>% rowwise() %>% mutate(result = get_winner_name(.))
warnings()
football_data %>% select(2:5) %>% rowwise() %>% mutate(result = get_winner_name())
football_data %>%
select(2:5) %>% mutate(get_winner_name(home_score, away_score, home_team, away_team))
get_winner_name <- function(home_score, away_score, home_team, away_team) {
if(home_score > away_score) {
return(home_team)
}
else if(home_score < away_score) {
return(away_team)
}
else {
return("Draw")
}
}
football_data %>%
select(2:5) %>% mutate(get_winner_name(home_score, away_score, home_team, away_team))
football_data %>%
select(2:5) %>% mutate(winner = get_winner_name(home_score, away_score, home_team, away_team))
football_data %>% slice(2)
football_data %>% slice(2) %>% get_winner_name()
get_winner_name <- function(match_row) {
if(match_row["home_score"] > match_row["away_score"]) {
return(match_row["home_team"])
}
else if(match_row["home_score"] < match_row["away_score"]) {
return(match_row["away_team"])
}
else {
return("Draw")
}
}
get_winner_name <- function(match_row) {
if(match_row["home_score"] > match_row["away_score"]) {
return(match_row["home_team"])
}
else if(match_row["home_score"] < match_row["away_score"]) {
return(match_row["away_team"])
}
else {
return("Draw")
}
}
football_data %>% slice(2) %>% get_winner_name()
football_data %>% get_winner_name()
football_data %>% rowwise() %>% get_winner_name()
football_data %>% apply(get_winner_name())
football_data %>% apply(., get_winner_name())
football_data %>% apply(., ,get_winner_name())
football_data %>% apply(., ,get_winner_name)
football_data %>% apply(., 1, get_winner_name)
football_data %>% mutate(winner = apply(., 1, get_winner_name))
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
2019-05-15 00:35:53 +02:00
shiny::runApp()
runApp()
install.packages("dt")
install.packages("DT")
install.packages(c("DT", "shiny"))
install.packages(c("DT", "shiny"))
shiny::runApp()
runApp()
runApp()
runApp()
exit()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
# Functions
get_matches_list <- function(first_team, second_team) {
matches <- football_data %>%
select(1:9) %>%
filter(home_team %in% c(first_team, second_team)
& away_team %in% c(first_team, second_team))
return(matches)
}
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
View(football_data_ext)
getBalance <- function(data, home_team, away_team) {
balance <- data %>%
group_by(., "winner") %>%
summarise(n = n())
return(balance)
}
test <- getBalance(football_data_ext, "England", "Scotland")
test
head(test)
balance <- football_data_ext %>% group_by(., "winner")
View(balance)
balance <- football_data_ext %>% aggregate(,. by="winner")
balance <- football_data_ext %>% aggregate(., by="winner")
balance <- football_data_ext %>% aggregate(., by="winner", FUN = sum())
balance <- football_data_ext %>% aggregate(., by="winner", FUN = sum
)
balance <- football_data_ext %>% aggregate(., by=list(.$winner), FUN = sum)
balance <- football_data_ext %>% aggregate(., by=list(as.numeric(.$winner)), FUN = sum)
View(balance)
balance <- football_data_ext %>% group_by(., .$winner)
View(balance)
balance <- football_data_ext %>% group_by(.$winner)
View(balance)
balance <- football_data_ext %>% group_by(winner)
View(balance)
balance <- football_data_ext %>% count(winner)
View(balance)
getBalance <- function(data, home_team, away_team) {
balance <- data %>%
count(winner, sort = TRUE)
return(balance)
}
View(test)
test <- get_matches_list("England", "Scotland")
View(test)
getMatchesList <- function(first_team, second_team) {
matches <- football_data_ext %>%
select(1:9) %>%
filter(home_team %in% c(first_team, second_team)
& away_team %in% c(first_team, second_team))
return(matches)
}
getMatchesList("England", "Scotland")
# Functions
getMatchesList <- function(first_team, second_team) {
matches <- football_data_ext %>%
filter(home_team %in% c(first_team, second_team)
& away_team %in% c(first_team, second_team))
return(matches)
}
getMatchesList("England", "Scotland")
test <- getMatchesList("England", "Scotland")
runApp()
getBalance(test, "England", "Scotland")
barplot(getBalance(
getMatchesList(input$first_team, input$second_team, football_data_ext)))
runApp()
bal <- getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))
bal <- getBalance(getMatchesList("England", "Scotland", football_data_ext))
bal
runApp()
runApp()
bal.n
bal <- getBalance(getMatchesList("England", "Scotland", football_data_ext))
bal.n
bal$n
runApp()
bal$n
runApp()
typeof(bal)
runApp()
runApp()
runApp()
runApp()
runApp()
View(bal)
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
2019-05-16 00:37:48 +02:00
shiny::runApp()
install.packages("shinythemes")
runApp()
runApp()
runApp()
View(test)
View(balance)
View(bal)
balancePercTest <- bal %>% mutate(percentage = n/sum(.$n))
head(balancePercTest)
runApp()
runApp()
runApp()
runApp()
runApp()
balPerc <- getBalancePercentage(
getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))
)
runApp()
runApp()
runApp()
runApp()
View(football_data)
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
View(football_data)
getMatchesList("England", "Scotland", football_data)
getMatchesList("England", "Scotland", football_data) %>% arrange()
getMatchesList("England", "Scotland", football_data) %>% arrange(decreasing=TRUE)
getMatchesList("England", "Scotland", football_data) %>% arrange(.,decreasing=TRUE)
getMatchesList("England", "Scotland", football_data) %>% arrange(.$date)
getMatchesList("England", "Scotland", football_data) %>% arrange(.$date, decreasing=TRUE)
getMatchesList("England", "Scotland", football_data) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% sort(date)
getMatchesList("England", "Scotland", football_data) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% sort(date, decreasing = TRUE)
football_data %>% select(date)
football_data %>% select(date) %>% min()
football_data %>% select(date) %>% format(date, "%Y")
football_data %>% select(date) %>% format(.$date, "%Y")
football_data %>% select(date) %>% typeof()
football_data %>% select(date) %>% format(as.Date(date, format="%Y-%m-%d"),"%Y")
test <- football_data %>% select(date)
test[1]
test %>% head(1)
test %>% head(1) %>% format(., "%Y")
test %>% head(1) %>% typeof
test %>% head(1) %>% typeof()
football_data %>% select(date) %>% min()
football_data %>% select(date)
football_data %>% select(date) %>% aggregate(., by=list(.), max)
football_data %>% min(.$date)
football_data %>% select(date) %>% summarise(min = min(date))
football_data %>% select(date) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% summarise(min = min(date))
football_data %>% select(date) %>% mutate(. = as.Date(date, "%Y-%m-%d")) %>% summarise(min = min(.))
football_data %>% select(date) %>% mutate(. = as.Date(., "%Y-%m-%d")) %>% summarise(min = min(.))
getDateFromData <- function(matchesData) {
return(
matchesData %>%
select(date) %>%
mutate(date = as.Date(date, "%Y-%m-%d"))
)
}
getDateFromData(football_data) %>%
summarise(max = max(date))
balance <- football_data %>%
count(winner, sort = TRUE)
return(balance)
runApp()
getDateFromData(football_data)
runApp()
runApp()
runApp()
runApp()
typeof(min_date_from)
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% as.Date()
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% as.Date(., format = "%Y-%m-%d")
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% as.Date(date, format = "%Y-%m-%d")
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% as.Date(date)
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% strptime(date, "%Y-%m-%d")
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% strptime(., "%Y-%m-%d")
getDateFromData(football_data) %>%
summarise(min = min(date))
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% top_n(1)
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% top_n(1) %>% typeof
runApp()
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% slice(1)
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% pull()
runApp()
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% pull() %>% typeof()
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% pull() %>% as.Date(., format = "%Y-%m-%d")
getDateFromData(football_data) %>%
summarise(min = min(date)) %>% pull() %>% as.Date(., format = "%Y-%m-%d") %>% typeof()
test <- getDateFromData(football_data) %>%
summarise(min = min(date)) %>% pull()
as.Date(test, "%Y-%m-%d")
as.Date(test, "%Y-%m-%d") %>% typeof()
test <- as.Date(test, "%Y-%m-%d")
typeof(test)
as.character(test)
test <- as.character(test)
test
typeof(test)
test <- as.Date(test, "%Y-%m-%d")
test
typeof(test)
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
test_date <- as.Date("2000-01-01", "%Y-%m-%d")
football_data %>% filter(as.Date(as.character(date, "%Y-%d-%m")) >= test_date)
runApp()
football_data %>%
filter(as.Date(as.character(date, "%Y-%d-%m")) >= as.Date(as.character(test_date, "%Y-%d-%m"))
& as.Date(as.character(date, "%Y-%d-%m")) <= as.Date(as.character(max_date_to, "%Y-%d-%m")))
football_data %>%
filter(as.Date(as.character(date, "%Y-%d-%m")) >= as.Date(as.character(test_date, "%Y-%d-%m")))
runApp()
install.packages("lubridate")
runApp()
runApp()
dateFrom <- as.Date(as.character(dateFrom, "%Y-%m-%d"))
runApp()
as_date(test)
test_date <- as_date(test)
test_date
typeof(test_date)
runApp()
runApp()
runApp()
football_data %>% filter(as_date(date) >= test_date)
runApp()
getMatchesList <- function(matchesData, first_team, second_team) {
return(
matchesData %>%
filter(home_team %in% c(first_team, second_team)
& away_team %in% c(first_team, second_team)) %>%
arrange()
)
}
getMatchesList(football_data, "England", "Scotland")
getMatchesList(football_data, "England", "Scotland") %>% filterByDate(min_date_from, max_date_to)
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
View(football_data_ext)
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
install.packages("shinydashboard")
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()