0

I'd like to take the result of a Quanteda package and add it to an existing spreadsheet. For example:

 newdf<- as.data.frame(kwic(x, keywords, window = 5, 
 valuetype = c("glob", "regex", "fixed"),case_insensitive = TRUE, ...))

This creates a dataframe with several columns. I want this to be added to the data that it came from (in this case x), then have NULL or NA for the rest.

Is mutate in dplyr the right thing? Or do I need something else?

Thanks!

Alex
  • 77
  • 1
  • 10

1 Answers1

0

The return from kwic() is already a data.frame, so no need for the as.data.frame(). You will not be able to "add this to x" however since the return from kwic() is one row per keyword match, where your original data x is a character or corpus object organised "row" per document.

However, you can create a corpus directly from the kwic object returned by the function, using corpus(kwic(x, ...)) or if you prefer piping,

require(magrittr)
kwic(x, ...) %>% corpus

Note of course that here, x, ... will be replaced by your arguments.

Ken Benoit
  • 14,454
  • 27
  • 50