Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Convert for loop into (?)apply in R

$
0
0

I need your help with these two for loops in R, because it takes literally hours to get the job done and I already tried a few to get the job myself done... :

for (i in 1:nrow(neg.sent.dictionary)){
    text <- gsub(neg.sent.dictionary$pattern[i], neg.sent.dictionary$replacement[i], text, fixed = 
    FALSE)
   }
for (i in 1:nrow(sent.dictionary)){
    neg.sent.dictionary$scored[i] <- ifelse(grepl(neg.sent.dictionary$feature[i], text, fixed = TRUE),
    TRUE, neg.sent.dictionary$scored[i])
   }

This is what (neg.)sent.dictionary looks like:
neg.sent.dictionary data
sent.dictionary data

And text is a huge character vector.

I would be very grateful if someone could help me!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>