<div dir="ltr">I'm trying to run a function on every row fulfilling a certain criterium, which returns a data frame - the idea is then to take the list of data frames and rbindlist them together for a totally separate data.table. (I'm extracting several URL links from each forum post, and tagging them with the forum post they came from). <div>
<br></div><div>I tried doing this with a data.table</div><div><br></div><div>a <- db[has_url == T, getUrls(text, id)]</div><div><br></div><div>and get the message</div><div><br></div><div><div>Error in `$<-.data.frame`(`*tmp*`, "id", value = c(1L, 6L, 1L, 2L, 4L, : </div>
<div> replacement has 11007 rows, data has 29787 </div></div><div><br></div><div style>Because some rows have several URLs... However, I don't care that these rowlengths don't match, I still want these rows :) I thought J would just let me execute arbitrary R code in the context of the rows as variable names, etc. </div>
<div style><br></div><div style>Here's the function it's running, but that shouldn't be relevant</div><div style><br></div><div style><div>getUrls <- function(text, id) {</div><div> matches <- str_match_all(text, url_pattern)</div>
<div> a <- data.frame(urls=unlist(matches))</div><div> a$id <- id</div><div> a</div><div>}</div><div><br></div><div><br></div><div style>Thanks, and thanks for an amazing package - data.table has made my life so much easier. It should be part of base, I think.</div>
<div style>Stian Haklev, University of Toronto</div></div><div><div><br></div>-- <br><a href="http://reganmian.net/blog">http://reganmian.net/blog</a> -- Random Stuff that Matters<br>
</div></div>