【发布时间】:2013-10-04 04:46:43
【问题描述】:
我正在尝试在满足特定条件的每一行上运行一个函数,该函数返回一个数据框 - 然后将数据框列表和 rbindlist 一起用于一个完全独立的 data.table。 (我从每个论坛帖子中提取几个 URL 链接,并用它们来自的论坛帖子标记它们)。
我尝试使用 data.table 进行此操作
getUrls <- function(text, id) {
matches <- str_match_all(text, url_pattern)
a <- data.frame(urls=unlist(matches))
a$id <- id
a
}
a <- db[has_url == TRUE, getUrls(text)]
并得到消息
Error in `$<-.data.frame`(`*tmp*`, "id", value = c(1L, 6L, 1L, 2L, 4L, :
replacement has 11007 rows, data has 29787
因为有些行有多个 URL...但是,我不在乎这些行长度不匹配,我仍然想要这些行 :) 我以为 J 会让我在上下文中执行任意 R 代码行作为变量名等。
【问题讨论】:
-
能否提供db的样本数据?顺便说一句,您在
getUrls(text中缺少)。此外,使用 TRUE 和 FALSE(而不是 T 和 F)被认为更安全。 -
感谢鼓励,见下文,欢迎提供更多反馈。
标签: r data.table