如何使用向量替换链接的数值?

时间:2019-06-18 06:55:46

标签: r web-scraping

例如链接:“ http://stats.espncricinfo.com/ci/engine/player/219889.html?class=1;spanmin1=01+Jan+2011;spanval1=span;template=results;type=batting;view=innings

我想使用向量替换上述链接的数值(219889),以获得不同的链接。

library(XML)
library(RCurl)

players = c(4578,272279,7133)

for (i in players) {
  read = HYPERLINK(CONCATENATE("http://stats.espncricinfo.com/ci/engine/player/",players[i],".html?class=1;spanmin1=01+Jan+2011;spanval1=span;template=results;type=batting;view=innings"))
}

1 个答案:

答案 0 :(得分:1)

sprintf%s%d一起使用

sprintf("http://stats.espncricinfo.com/ci/engine/player/%s.html?class=1;spanmin1=01+Jan+2011;spanval1=span;template=results;type=batting;view=innings",players)

paste0

paste0("http://stats.espncricinfo.com/ci/engine/player/", players, ".html?class=1;spanmin1=01+Jan+2011;spanval1=span;template=results;type=batting;view=innings")