0

I have a data frame (dat1) as such:

|Home Team|Away Team|...|Goals Scored|Goals Conceded|
|----|----|---|------------|--------------|
|A|B|...|NA|NA|
|B|C|...|NA|NA|
|D|E|...|NA|NA|

with another 1000 rows including other games

With another data frame (dat2) that includes:

|Team...|Goals Scored|Goals Conceded|
|-------|------------|--------------|
|A|1|0|
|B|1|1|
|C|3|1|
|D|4|2|
|E|2|2|

I'd like to write some code that inputs the Goals Scored and Goals Conceded from dat2 into dat1. I can't figure out the conditional statement required to do it though. TIA

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • 1
    Pivot `dat2` from long to wide, then join. Don't use loops. [Here's the FAQ on doing joins in R](https://stackoverflow.com/q/1299871/903061), and [here's the FAQ on going from long to wide](https://stackoverflow.com/q/5890584/903061). – Gregor Thomas Oct 26 '22 at 20:45

0 Answers0