如何使用 R 向量化来删除这个 for 循环?
library(stringr)
url <- c("http://www.slate.fr/france/87869/mehdi-nemmouche-bruxelles", "http://www.slate.fr/story/87347/turquie-opposition-geek", "http://www.slate.fr/grand-format/paysages-debarquement-photos-1944-aujourdhui")
for (i in 1:length(url)) {
a[i]<-str_match(url[i], "http://.*slate.fr/(.*?)/")[2]
}
这不起作用:
a<-str_match(url, "http://.*slate.fr/(.*?)/")[2]