我正在处理NBA数据,有一列城市代码不正确。(CHO代替CHA,BRK代替BKN等(。
我想把不正确的缩写改成正确的缩写。我对此很陌生。
for (x in most_recent$TM){
if (x == "CHO"){
x == "CHA"
}
}
你在找这样的东西吗?
team_abb_long2short = c('Atlanta Hawks' = 'ATL',
'Boston Celtics' = 'BOS',
'Brooklyn Nets' = 'BKN',
'Charlotte Bobcats' = 'CHA',
'Chicago Bulls' = 'CHI',
'Cleveland Cavaliers' = 'CLE',
'Dallas Mavericks' = 'DAL',
'Denver Nuggets' = 'DEN',
'Detroit Pistons' = 'DET',
'Golden State Warriors' = 'GSW',
'Houston Rockets' = 'HOU',
'Indiana Pacers' = 'IND',
'Los Angeles Clippers' = 'LAC',
'Los Angeles Lakers' = 'LAL',
'Memphis Grizzlies' = 'MEM',
'Miami Heat' = 'MIA',
'Milwaukee Bucks' = 'MIL',
'Minnesota Timberwolves' = 'MIN',
'New Orleans Hornets' = 'NOH',
'New York Knicks' = 'NYK',
'Oklahoma City Thunder' = 'OKC',
'Orlando Magic' = 'ORL',
'Philadelphia 76ers' = 'PHI',
'Phoenix Suns' = 'PHX',
'Phoenix Suns' = 'PHO',
'Portland Trail Blazers' = 'POR',
'Sacramento Kings' = 'SAC',
'San Antonio Spurs' = 'SAS',
'Toronto Raptors' = 'TOR',
'Utah Jazz' = 'UTA',
'Washington Wizards' = 'WAS')
flip_named_vector = function(x){
ret = names(x)
names(ret) = x
ret
}
team_abb_short2long = flip_named_vector(team_abb_long2short)
team_abb_short2long
ATL BOS BKN CHA CHI
"Atlanta Hawks" "Boston Celtics" "Brooklyn Nets" "Charlotte Bobcats" "Chicago Bulls"
CLE DAL DEN DET GSW
"Cleveland Cavaliers" "Dallas Mavericks" "Denver Nuggets" "Detroit Pistons" "Golden State Warriors"
HOU IND LAC LAL MEM
"Houston Rockets" "Indiana Pacers" "Los Angeles Clippers" "Los Angeles Lakers" "Memphis Grizzlies"
MIA MIL MIN NOH NYK
"Miami Heat" "Milwaukee Bucks" "Minnesota Timberwolves" "New Orleans Hornets" "New York Knicks"
OKC ORL PHI PHX PHO
"Oklahoma City Thunder" "Orlando Magic" "Philadelphia 76ers" "Phoenix Suns" "Phoenix Suns"
POR SAC SAS TOR UTA
"Portland Trail Blazers" "Sacramento Kings" "San Antonio Spurs" "Toronto Raptors" "Utah Jazz"
WAS
"Washington Wizards"
team_abb_long2short
Atlanta Hawks Boston Celtics Brooklyn Nets Charlotte Bobcats Chicago Bulls
"ATL" "BOS" "BKN" "CHA" "CHI"
Cleveland Cavaliers Dallas Mavericks Denver Nuggets Detroit Pistons Golden State Warriors
"CLE" "DAL" "DEN" "DET" "GSW"
Houston Rockets Indiana Pacers Los Angeles Clippers Los Angeles Lakers Memphis Grizzlies
"HOU" "IND" "LAC" "LAL" "MEM"
Miami Heat Milwaukee Bucks Minnesota Timberwolves New Orleans Hornets New York Knicks
"MIA" "MIL" "MIN" "NOH" "NYK"
Oklahoma City Thunder Orlando Magic Philadelphia 76ers Phoenix Suns Phoenix Suns
"OKC" "ORL" "PHI" "PHX" "PHO"
Portland Trail Blazers Sacramento Kings San Antonio Spurs Toronto Raptors Utah Jazz
"POR" "SAC" "SAS" "TOR" "UTA"
Washington Wizards
"WAS"