Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

r - how to combine columns that have same name

I am trying to figure out how to combine items that are similarly named in the same column.

For instance the data I have looks like this:

Home_Team        Goals_from_Home     Away_Team   Goals_Away_From_Home
Man United       2                   Leicester          1
Arsenal          2                   Newcastle          0
Man United       1                   Newcastle          0

How would I go about combing everything that has the same name and team into one? I am using this dataset: https://data.world/chas/2018-2019-premier-league-matches/workspace/file?filename=2018-2019.csv

And so far what I have done is to make everything into a data frame and now I am stuck from there.

My code as it looks:


soccer_data <- read.csv("2018-2019.csv")

home_team <- c(soccer_data$HomeTeam)
goals_at_home <- c(soccer_data$FTHG)
goals_away_from_home <- c(soccer_data$FTAG)
away_team <- c(soccer_data$AwayTeam)

soccer_data_frame <- data.frame(home_team, goals_at_home, away_team, goals_away_from_home)


question from:https://stackoverflow.com/questions/65877619/how-to-combine-columns-that-have-same-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...