简体   繁体   中英

How do I combine two words into one string?

I have a little syntax problem, I am trying to perform sentiment analysis based on positive words , negative words and negative-positive words (eg="not able"), basically 3 dictionaries.

For positive and negative dictionaries the world classificiation is pretty easy I just use:

scan('positive.txt', what='character', comment.char=";")

and the results is pretty much all the single positive words however when it comes to negative-positive words it gets tricky, when I use

scan('negative-positive.txt', what='character', comment.char=";")

the result is the following: enter image description here

How can I make "not + adjective" as a single word not a divided one?

If you want to combine two strings/characters in R, you can use this:

combined_word<-paste0("positive","negative")
print(combined_word)

Output

[1] "positivenegative"

You can join the results using paste along the lines of what ashwin agrawal demonstrated. However, this solution will only work if all of your positive-negative phrases contain exactly two words (or the same number of words, actually).

It is typically better to eliminate problems at the root – ie read the data correctly, in the first place. I am not sure what your files look like, but I assume that you have one phrase per line. In that case, you may want to set the sep parameter to indicate what separates the phrases (newline in that case):

scan("foo.txt", what="character", sep="\n", comment.char=";")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM