I am trying to make my code display the mean attendance of a specified country in a new column. When I run the code below (Should be an image) I get the table also listed in the image. Can anyone explain how to display only the column of the specified country name and the mean attendance in the new column and explain what I am doing wrong? Thank you
EDIT: sorry I'm obviously new at this, my code is
WorldCupMatches %>%
select(Home.Team.Name, Attendance) %>%
group_by(Home.Team.Name == "USA") %>%
mutate(AVG_Attendance = mean(Attendance, na.rm = T))
so to explain more, worldcupmatches is a dataframe and it has columns named "home.team.names" and "Attendance." I am trying to add a column by mutating and I want the mutated column to show the mean attendance for a country. The country i am looking for in this particular situation is USA. I also want the output to only display the columns "home.team.name" (with the USA as the home team), attendance and the mutated column that would be the mean attendance.
Thank you all for the help i got a lot of great answers!