I'm clearly going about this incorrectly, so looking for some advice (newbie R programmer here...) Need to split up a data frame of the AFINN word list into two new vectors (one for positive words and one for negative words). I used subset, but have a few lines here. What's a better way to combine these lines into one line?
# read the "AFINN" dataset and assign it into a variable called "AFINN"
AFINN <- read.delim("AFINN.txt", header=FALSE)
AFINN
# change column names to "Word" and "Score"
colnames(AFINN) <- c("Word","Score")
#split the AFINN data frame up into positive and negative word vectors
posAFINN <- subset(AFINN, Score >= 0)
posAFINN <- posAFINN[,-2]
posAFINN
negAFINN <- subset(AFINN, Score <= 0)
negAFINN <- negAFINN[,-2]
negAFINN
>=and just<? If sosplit(AFINN$Word, AFINN$Score >= 0)will do it. Orlapply(split(AFINN, AFINN$Score >= 0), '[', -2, drop = FALSE)split(AFINN$Word, sign(AFINN$Score))is an alternative putting zero in a third vector.