переименовать соединенные столбцы на основе формулы?

#r

Вопрос:

Я пытаюсь объединить 2 набора данных и переименовать объединенные данные, чтобы они были привязаны к соединяемому столбцу. В данном случае я учитываю рост и вес всех игроков, которые начали конкретную бейсбольную игру. Я получаю ошибку, когда я иду переименовывать, указывая на знак = (например, = в переименовании(paste0(идентификатор,»_Weight») = вес).

 library(tidyverse)
library(Lahman)
Baseball_People <- Lahman::People %>% select(retroID,weight,height) %>% mutate(BMI = weight / (height * height) * 703)

retro_output <- tibble()
for {i in 2010:2020)
{
retro_temp <- read_csv(paste0("retro_year_",i),col_names = c("Date","DoubleHeader","DayOfWeek","VisitingTeam","VisitingTeamLeague","VisitingTeamGameNumber","HomeTeam","HomeTeamLeague","HomeTeamGameNumber","VisitorRunsScored","HomeRunsScore","LengthInOuts","DayNight","CompletionInfo","ForfeitInfo","ProtestInfo","ParkID","Attendence","Duration","VisitorLineScore","HomeLineScore","VisitorAB","VisitorH","VisitorD","VisitorT","VisitorHR","VisitorRBI","VisitorSH","VisitorSF","VisitorHBP","VisitorBB","VisitorIBB","VisitorK","VisitorSB","VisitorCS","VisitorGDP","VisitorCI","VisitorLOB","VisitorPitchers","VisitorER","VisitorTER","VisitorWP","VisitorBalks","VisitorPO","VisitorA","VisitorE","VisitorPassed","VisitorDB","VisitorTP","HomeAB","HomeH","HomeD","HomeT","HomeHR","HomeRBI","HomeSH","HomeSF","HomeHBP","HomeBB","HomeIBB","HomeK","HomeSB","HomeCS","HomeGDP","HomeCI","HomeLOB","HomePitchers","HomeER","HomeTER","HomeWP","HomeBalks","HomePO","HomeA","HomeE","HomePassed","HomeDB","HomeTP","UmpireHID","UmpireHName","Umpire1BID","Umpire1BName","Umpire2BID","Umpire2BName","Umpire3BID","Umpire3BName","UmpireLFID","UmpireLFName","UmpireRFID","UmpireRFName","VisitorManagerID","VisitorManagerName","HomeManagerID","HomeManagerName","WinningPitcherID","WinningPitcherName","LosingPitcherID","LosingPitcherNAme","SavingPitcherID","SavingPitcherName","GameWinningRBIID","GameWinningRBIName","VisitorStartingPitcherID","VisitorStartingPitcherName","HomeStartingPitcherID","HomeStartingPitcherName","VisitorBatting1PlayerID","VisitorBatting1Name","VisitorBatting1Position","VisitorBatting2PlayerID","VisitorBatting2Name","VisitorBatting2Position","VisitorBatting3PlayerID","VisitorBatting3Name","VisitorBatting3Position","VisitorBatting4PlayerID","VisitorBatting4Name","VisitorBatting4Position","VisitorBatting5PlayerID","VisitorBatting5Name","VisitorBatting5Position","VisitorBatting6PlayerID","VisitorBatting6Name","VisitorBatting6Position","VisitorBatting7PlayerID","VisitorBatting7Name","VisitorBatting7Position","VisitorBatting8PlayerID","VisitorBatting8Name","VisitorBatting8Position","VisitorBatting9PlayerID","VisitorBatting9Name","VisitorBatting9Position","HomeBatting1PlayerID","HomeBatting1Name","HomeBatting1Position","HomeBatting2PlayerID","HomeBatting2Name","HomeBatting2Position","HomeBatting3PlayerID","HomeBatting3Name","HomeBatting3Position","HomeBatting4PlayerID","HomeBatting4Name","HomeBatting4Position","HomeBatting5PlayerID","HomeBatting5Name","HomeBatting5Position","HomeBatting6PlayerID","HomeBatting6Name","HomeBatting6Position","HomeBatting7PlayerID","HomeBatting7Name","HomeBatting7Position","HomeBatting8PlayerID","HomeBatting8Name","HomeBatting8Position","HomeBatting9PlayerID","HomeBatting9Name","HomeBatting9Position","AdditionalInfo","AcquisitionInfo"))
for (j in 1:2)
{
  if(j == 1)
  {
    home_away = "Visitor"
  }
  else 
  { home_away = "Home"
  }
  for (k in 0:10)
  {  
    if (K != 0)
    {
      id <- paste0(home_away,"Batting",k,"PlayerID")
    }
    else
    {
      id <- paste0(home_away,"StartingPitcherID")
    }
    
    Retro_Temp_2 <- left_join(Retro_Temp,Baseball_People, by = c(id = "retroID"))
    print(paste0(id,"_Weight"))
    
    Retro_Temp_2 <- Retro_Temp_2 %>% rename((paste0(id,"_Weight")) = "weight"#,paste0(id,"_Height") = "height",paste0(id,"_BMI") = "BMI")
}
}
Retro_output <- bind_rows(Retro_output,Retro_Temp_2)
...
 

свободный пример таблицы retrosheet (идентификатор игры по умолчанию разделен на несколько столбцов, но здесь это не имеет значения, и вы будете играть до 9 игроков).

GameID Посетители startingpitcherid Посещение1пользовательский идентификатор Идентификатор посетителя 2playerid Домашний питчерид HomeBatting1PlayerID HomeBatting2PlayerID
АНА19990902 aardd001 aased001 tktktk01 tkadd02 tktkee01 aarot101