Apology for not submitting Reprex. I tried but having issues with Reprex selection add-in.
Problem below with naming. Get error on 2B column name, but if I add "" like I did with 3B all is fine. Do not understand what is wrong with naming syntax. Have same issue with summation function. But will not accept name even when "" added. Thanks for any help. JD
# collect all current batters stats from https://www.rotowire.com/baseball/stats.php
season_batters <- read_csv("all_batter.txt", col_names = TRUE) %>%
filter(PA > 0, Tm != "TOT")
# filter for more than 25 at bats and calculate current batting average
bat_avg <- season_batters %>%
filter(AB > 25) %>%
select(Name, Tm, G, AB, R, H, 2B,"3B", HR, SO, BB, OBP, SLG, OPS, "OPS+", TB) %>%
mutate(average = H/AB)
OUTPUT
Rows: 1523 Columns: 30
-- Column specification ----------------------------------------------------------------------------
Delimiter: ","
chr (4): Name, Tm, Lg, Pos Summary
dbl (26): Rk, Age, G, PA, AB, R, H, 2B, 3B, HR, RBI, SB, CS, BB, SO, BA, OBP, SLG, OPS, OPS+, TB...
i Use spec()
to retrieve the full column specification for this data.
i Specify the column types or set show_col_types = FALSE
to quiet this message.
Error: unexpected symbol in:
" filter(AB > 25) %>%
select(Name, Tm, G, AB, R, H, 2B"