R 使某些列依赖于我的数据帧

R 使某些列依赖于我的数据帧,r,R,我有一个网球运动员数据框架,其中包含过去网球比赛的结果。我遇到的问题是,数据的匹配统计数据都在1行中,有20列输入。所以我想知道如何附加到与player1性能相关的某些列变量,反之亦然。 所以R知道这是一种比较或vs类型的情况 library(readxl) library(dbplyr) library(dplyr) # Naming players to look up pl1<- 'Novak Djokovic' pl2<- 'Roger Federer' #Identi

我有一个网球运动员数据框架,其中包含过去网球比赛的结果。我遇到的问题是,数据的匹配统计数据都在1行中,有20列输入。所以我想知道如何附加到与player1性能相关的某些列变量,反之亦然。 所以R知道这是一种比较或vs类型的情况

library(readxl)
library(dbplyr)
library(dplyr)

# Naming players to look up

pl1<- 'Novak Djokovic'
pl2<- 'Roger Federer'

#Identifying the 2 players above and there last 20 matches
atpd <- subset(ATP_Data, ATP_Data$`player1` == pl1 |ATP_Data$`player2` == pl1 |ATP_Data$`player1` == pl2 | ATP_Data$`player2` == pl2  )
tail(select(atpd,1,2,5,6,7,19,20,11,12,14,15,16), n=20)`

您好,您是否可以使用
dput(head(df,n))
添加一些样本数据,其中n是您认为足以实现再现性的最小行数?干杯上述方法有用吗?
   player1          player2            date                round  surface probw  probl rank_winner rank_loser won_by lost_by total
   <chr>            <chr>              <dttm>              <chr>  <chr>   <dbl>  <dbl>       <dbl>      <dbl>  <dbl>   <dbl> <dbl>
 1 Roger Federer    Filip Krajinovic   2018-10-23 00:00:00 First  I.hard  0.873 0.127            3         35     -4       4    28
'structure(list(player1 = c("Novak Djokovic", "Novak Djokovic", 
"Roger Federer", "Ivo Karlovic", "Roger Federer", "Roger Federer"
), player2 = c("Dusan Lajovic", "Sergiy Stakhovsky", "John Millman", 
"Novak Djokovic", "James Duckworth", "Grigor Dimitrov"), tournament = 
c("Qatar ExxonMobil Open - Doha", 
"Qatar ExxonMobil Open - Doha", "Brisbane International - Brisbane", 
"Qatar ExxonMobil Open - Doha", "Brisbane International - Brisbane", 
"Brisbane International - Brisbane"), class = c("world tour", 
"world tour", "world tour", "world tour", "world tour", "world tour"
), date = structure(c(1420502400, 1420588800, 1420675200, 1420675200, 
1420761600, 1420848000), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
round = c("First", "Second", "Second", "1/4", "1/4", "1/2"
), surface = c("Hard", "Hard", "Hard", "Hard", "Hard", "Hard"
), result = c("6-2 6-1", "6-2 6-1", "4-6 6-4 6-3", "6-7(2) 7-6(6) 6-4", 
"6-0 6-1", "6-2 6-2"), odds_w = c(1.071, 1.03, 1.067, 12, 
1.074, 1.355), odds_l = c(10.44, 17.5, 11.25, 1.067, 11.25, 
3.55), rank_winner = c(1, 1, 2, 27, 2, 2), rank_loser = c(68, 
57, 153, 1, 125, 11), sets = c("2-0", "2-0", "2-1", "2-1", 
"2-0", "2-0"), won_by = c(-9, -9, -3, -2, -11, -8), lost_by = c(9, 
9, 3, 2, 11, 8), total = c(15, 15, 29, 36, 13, 16), gp1 = c(12, 
12, 16, 19, 12, 12), gp2 = c(3, 3, 13, 17, 1, 4), probw = 
c(0.933706816059757, 
0.970873786407767, 0.937207122774133, 0.0833333333333333, 
0.931098696461825, 0.738007380073801), probl = c(0.0662931839402428, 
0.029126213592233, 0.0627928772258669, 0.916666666666667, 
0.0689013035381751, 0.261992619926199)), row.names = c(NA, 
6L), class = c("tbl_df", "tbl", "data.frame"))'