我希望将非永久性向量合并到一个数据框中,
使用以下循环创建这些向量
for (i in campagin_id){
h <- basicHeaderGatherer()
doc <- getURI(paste0(automations_url,
"/",i,
"?apikey=",accessToken,
"&count=",pagination), headerfunction = h$update)
assign(paste0('web_id',i),c(i,as.integer(substring(h$value()[as.integer(grep(SearchTerm, h$value()))],
as.integer(regexpr(SearchTerm,h$value()[as.integer(grep(SearchTerm, h$value()))]))+nchar(SearchTerm)-1,as.integer(regexpr(SearchTerm,h$value()[as.integer(grep(SearchTerm, h$value()))]))+nchar(SearchTerm)+StringLength-2))))
}
我收到了矢量列表,我喜欢用类似的rbind来填充它们
rbind(web_id0f09cc8ddd,web_id18a71f70a8)
问题是,我不知道会有多少向量,但我只知道向量名称的开头,所以我试图运行以下循环
for (i in campagin_id) {
web_id <- do.call("rbind",list(paste0('web_id',i)))
}
但它只向数据框插入一个向量
campaign_id包含我在特定时间内需要的所有i值
由于
答案 0 :(得分:1)
do.call
是正确的想法,但rbind
是一个缓慢的操作。你应该一次一个地将你的向量添加到一个列表中,然后在最后做一个rbind
,这样的事情(未经测试,很明显,因为这个例子不可重现,但它应该给出你的想法):
result_list = list(length = length(campagin_id))
for (i in campagin_id) {
h <- basicHeaderGatherer()
doc <- getURI(
paste0(
automations_url,
"/",
i,
"?apikey=",
accessToken,
"&count=",
pagination
),
headerfunction = h$update
)
result_list[[i]] = c(i, as.integer(
substring(
h$value()[as.integer(grep(SearchTerm, h$value()))],
as.integer(regexpr(SearchTerm, h$value()[as.integer(grep(SearchTerm, h$value()))])) +
nchar(SearchTerm) - 1,
as.integer(regexpr(SearchTerm, h$value()[as.integer(grep(SearchTerm, h$value()))])) +
nchar(SearchTerm) + StringLength - 2
)
))
}
results = do.call(rbind, result_list)