You can't store a data frame in a vector, but you can inside a list. The below code takes a vector of 4 team names, scrapes them all, and stores each team table in its own element inside of the list named list_df
require(tidyverse)
require(rvest)
fn_scrape <- function(.url1, .team, .url2){
Sys.sleep(1.0) # wait one second in-between scrapes for ethical scraping
paste0(.url1, .team, .url2) %>% # build the url to be scraped by combining team name with url sub strings
read_html() %>% # scrape the html
html_node(., '#sgl-basic') %>% # pull the html element that corresponds to the table
html_table() # auto-format the table
}
## Create variables that store the url substrings that come before and after the team name in the URL
url_sub1 <- 'https://www.sports-reference.com/cbb/schools/'
url_sub2 <- '/2021-gamelogs.html'
# Assign the name of the university to be scraped
team <- c('kansas-state', 'kansas', 'texas-tech', 'texas')
## Here we do the actual scraping
list_df <- team %>%
map(.x, .f = ~fn_scrape(.url1 = url_sub1, .team = .x, .url2 = url_sub2))