[R] Calculating distance between words in string

Karl josip.2000 at gmail.com
Fri Nov 6 12:28:05 CET 2015

Hi All,

Using R for text processing is quite new to me, while I have found a lot of
useful functions and I'm beginning to learn regex, I need help with the
following task. How do I calculate the distance between words?

That is, given a specific keyword, I need to assign labels to the other
words based on the distance (number of words) to this keyword.

For example, if the keyword is "amet" and the string of words is:
 "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
 -> "dolor" would get a value of -2
 -> "elit" would get a value of 3

If the sentence contains more than one instance of the keyword, I need
values for each instance. Moreover, one can assume that I can split my data
into sentences, so there is no need to search and recognize sentences (this
is a separate problem).

Thank you!

Best regards,

	[[alternative HTML version deleted]]

More information about the R-help mailing list