From 9bd382f9555898c23ce45fb9fc93e0ccfe2203a4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 19 Jul 2020 18:40:10 +0200 Subject: [PATCH] actor_merger: fix to generate bogus sentiment columns --- R/actor_merger.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/actor_merger.R b/R/actor_merger.R index 6ddd0b5..d5c5d63 100644 --- a/R/actor_merger.R +++ b/R/actor_merger.R @@ -52,11 +52,6 @@ actor_merger <- function(df, actors_meta, actor_groups = NULL) { text_sent <- df[,.SD, .SDcols = c('id', 'doctype',grep('text\\.',names(df), value = T))] - ## Unnest to sentence level - df <- df[,lapply(.SD, unlist, recursive=F), - .SDcols = c('sentence_id', 'sent_sum', 'words', 'sent_words','ids'), - by = list(id,publication_date)] - ## Create bogus variables if sentiment is not scored if(!"sent_sum" %in% colnames(df)) { df <- df[,.( @@ -66,6 +61,13 @@ actor_merger <- function(df, actors_meta, actor_groups = NULL) { ),.SDcols = -c('sent_words','sent_sum')] } + ## Unnest to sentence level + df <- df[,lapply(.SD, unlist, recursive=F), + .SDcols = c('sentence_id', 'sent_sum', 'words', 'sent_words','ids'), + by = list(id,publication_date)] + + + text_noactors <- df[lengths(ids) == 0L, .(noactor.sent = sum(sent_sum)/sum(words), noactor.sent_sum = sum(sent_sum),