I'm simply trying to take a column with game scores formatted like so "0-0", "0-2", etc. I want each teams score in a separate column which seems tailor made to use the "-" as the split key. I was able to use the following code to create a data frame with the split and append it to my database, however when i converted the variable type to either integer or numeric, it gave me completely different scores and I have no idea why. Finally, I just want to create a simple differential column too at the end but I think the problem spawned before that step.
Anyway, is there a better way to do this that might avoid this issue?
test <- as.data.frame(str_split(NBA_Clutch$Score, "-", simplify = TRUE))
NBA_Clutch$Home_Score <- as.integer(test$V2)
NBA_Clutch$Away_Score <- as.integer(test$V1)
#oops, change these to numeric variables
NBA_Clutch$Home_Score <- as.integer(NBA_Clutch$Home_Score)
NBA_Clutch$Away_Score <- as.integer(NBA_Clutch$Away_Score)
#how many points home team is winning by
NBA_Clutch <- NBA_Clutch %>%
mutate(Home_Team_Margin = Home_Score - Away_Score)