在下面的图像中,您可以看到有12个团队对象和6个时间对象。当我将此变量添加到Dataframe中时,它显然不适合并出现错误。有没有一种方法可以复制时间,使其显示两次,在同一场比赛中,名字出现1次,底部出现1次?
library(rvest)
library(dplyr)
library(tm)
library(stringi)
library(readr)
today <- Sys.Date()#+1
today <- gsub("-", "", today, fixed=TRUE)
url <- read_html(paste0('https://classic.sportsbookreview.com/betting-odds/nhl-hockey/?date=', as.character(today)))
gametime <- url %>%
html_nodes('.eventLine-time .eventLine-book-value') %>%
html_text()
teams <- url %>%
html_nodes('.team-name a') %>%
html_text()
roster <- data.frame(gametime = time, TEAM = teams)
编辑中:gametime = rep(gametime,each = 2)
library(rvest)
library(dplyr)
library(tm)
library(stringi)
library(readr)
today <- Sys.Date()#+1
today <- gsub("-", "", today, fixed=TRUE)
url <- read_html(paste0('https://classic.sportsbookreview.com/betting-odds/nhl-hockey/?date=', as.character(today)))
gametime <- url %>%
html_nodes('.eventLine-time .eventLine-book-value') %>%
html_text()
gametime = rep(gametime, each=2)
teams <- url %>%
html_nodes('.team-name a') %>%
html_text()
roster <- data.frame(gametime = time, TEAM = teams)
答案 0 :(得分:1)
rep(gametime, each=2)
将复制gametime
中的每个元素。