Cannot seem to nut out a solution, I don't get any errors when I run each line of code. The code appears to work when I check it but then when I try to display it in a chart or histogram the renam hasn't worked nor does the fct_recode stick!
So new at this
load libraries
library(readr)
library(tidyverse)
library(tidyr)
library(stringr)
library(ggplot2)
library(dplyr)
library(forcats)
read ashes.csv and load data
ashes <- read_csv("~/ashes.csv")
ashes
create ashes tibble
ashes_data <- tibble(ashes)
ashes_data
apply long format
ashes_long <- gather(ashes ,key='Innings', value = "description",4:13 )
ashes_long
extract values into new columns
ashes_match <- str_match(ashes_long$description, "Batting at number (\d+), scored (\d+) runs from (\d+) balls including 6 fours and 0 sixes.")
ashes_match
combine ashes_long and ashes_match into ashes_study then rename 3 and 4 and drop columns with NA
ashes_study <-cbind(ashes_long,ashes_match)
rename(ashes_study, scored = 3
, balls = 4
)
drop_na(ashes_study)
view(ashes_study)
change column type for scored and balls to integers
ashes_study$scored <- as.integer(ashes_study$scored)
ashes_study$balls <- as.integer(ashes_study$balls)
view(ashes_study)
recode factors for role and team
fct_recode(ashes_study$team,
England = "England",
England = "English",
Australia = "Australia"
)
fct_recode(ashes_study$role,
Batter = "bat",
Batter = "batting",
Batter = "batsman",
Wicketkeeper = "wicketkeeper",
Bowler = "bowl",
Bowler = "bowler",
Allrounder = "all-rounder",
Allrounder = "allrounder",
Allrounder = "all rounder"
)
Histogram
ggplot(ashes_study,aes(x = team)) + geom_bar()
combine ashes_long and ashes_match into ashes_study then rename 3 and 4 and drop columns with NA
ashes_study <-cbind(ashes_long,ashes_match)
rename(ashes_study, scored = 3
, balls = 4
)
drop_na(ashes_study)
view(ashes_study)
change column type for scored and balls to integers
ashes_study$scored <- as.integer(ashes_study$scored)
ashes_study$balls <- as.integer(ashes_study$balls)
view(ashes_study)