Question

I'm currently doing sentiment and emotion analysis of Twitter's data using R sentiment package and need to add new words to the subjectivity and emotion lexicons used by the package as there are some words that carry specific sentiment and emotion in the topic that I analyze.

Does anyone know how to add words to the lexicon using the R sentiment package itself or any other R command? I have searched in the documentation but cannot find any means to do so.

Was it helpful?

Solution

Both the subjectivity & emotion lexicon when read in (say, as csv) construct a data frame for you. Adding entries to a data frame can be done using the rbind() function.

> patientID <- c(1, 2, 3, 4)
> age <- c(25, 34, 28, 52)
> diabetes <- c("Type1", "Type2", "Type1", "Type1")
> status <- c("Poor", "Improved", "Excellent", "Poor")
> patientdata <- data.frame(patientID, age, diabetes, status)
> patientdata
patientID age diabetes status
1 1 25 Type1 Poor
2 2 34 Type2 Improved
3 3 28 Type1 Excellent
4 4 52 Type1 Poor
> patientID <- c(10, 20, 30, 40)
> age <- c(50, 68, 56, 104)
> diabetes <- c("Type4", "Type5", "Type6", "Type7")
> status <- c("Poorish", "Improving", "Excellento", "Poorish")
> patientdata1 <- data.frame(patientID, age, diabetes, status)
> patientdata1
patientID age diabetes status
1 10 50 Type4 Poorish
2 20 68 Type5 Improving
3 30 56 Type6 Excellento
4 40 104 Type7 Poorish
> concatPD <- rbind(patientdata,patientdata1)
> concatPD
patientID age diabetes status
1 1 25 Type1 Poor
2 2 34 Type2 Improved
3 3 28 Type1 Excellent
4 4 52 Type1 Poor
5 10 50 Type4 Poorish
6 20 68 Type5 Improving
7 30 56 Type6 Excellento
8 40 104 Type7 Poorish
>

I simply added the weird types of diabetes to ensure that the 2 frames are distinguished. :-) In other words, you can create our own csv, read it (thereby creating another data frame) & rbind them. Ensure that the columns of both data frames are in sync.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top