Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用data.table列中的参数按引用更新_R_Data.table - Fatal编程技术网

R 使用data.table列中的参数按引用更新

R 使用data.table列中的参数按引用更新,r,data.table,R,Data.table,我有以下数据表和函数,用于提取参数并将其作为列添加到数据表中: library(stringr) library(data.table) pq <- c("cm_mmc=MSN-_-Exact-_-BrandExact-_-CheddarCheese" ,"cm_mmc=Google-_-cheeseTypes-_-cheddar-_-cheesedelivered&gclid=CMXyy2D81MsCFcsW0w0dMVoPGw" ,"cm_mmc=MSN-_-worl

我有以下数据表和函数,用于提取参数并将其作为列添加到数据表中:

library(stringr)
library(data.table)

pq <- c("cm_mmc=MSN-_-Exact-_-BrandExact-_-CheddarCheese"
  ,"cm_mmc=Google-_-cheeseTypes-_-cheddar-_-cheesedelivered&gclid=CMXyy2D81MsCFcsW0w0dMVoPGw"
  ,"cm_mmc=MSN-_-worldcitiesuslocations-_-cheese-_-cheeseshops"
  ,"cm_mmc=MSN-_-worldcitiesuslocations-_-cheese-_-cheeseshops")


rq <- c("q=cheese&src=IE-SearchBox&FORM=IESR02",
                   "sa=L",
                   "q=london+cheese+shop&src=IE-TopResult&FORM=IETR02&pc=WCUG",
                   "q=london+cheese+shop&src=IE-TopResult&FORM=IETR02&pc=WCUG")

DT = data.table(page_urlquery = pq, refr_urlquery = rq)

# Extracts a paramater from the relevant query and adds it to the table as a column
extract_param <- function(dt, source = c("page_urlquery", "refr_urlquery"), param_name){
  source <- match.arg(source)
  regexp <- paste("(?i)", param_name, "=([^&]+)", sep="")
  col_name <- switch(source
                     ,"page_urlquery" = paste("url_", param_name, sep = "")
                     ,"refr_urlquery" = paste("ref_", param_name, sep = "")
  )

  dt[,(col_name):= str_match((source), regexp)[,2]]
}

它创建列,但内容为空。我认为数据表源参数中的语法有问题。我缺少什么?

将函数中的代码从

dt[,(col_name):= str_match((source), regexp)[,2]]

dt[,(col_name):= str_match((source), regexp)[,2]]
  dt[,(col_name):= str_match(get(source), regexp)[,2]]