R 删除柠檬化后的空间

R 删除柠檬化后的空间,r,lemmatization,R,Lemmatization,我只是简单地将一个字符向量化。问题是,柠檬化在单词之间创造了一个由破折号统一的空间(例如,短期变为短期)。我的字符向量充满了这些单词,所以我想找到一种方法来消除这种失真 让我举一个例子: text <- c("Stackoverflow is a great website where you can find great and very skilled people who are so kind to solve your coding problems. In the short-

我只是简单地将一个字符向量化。问题是,柠檬化在单词之间创造了一个由破折号统一的空间(例如,短期变为短期)。我的字符向量充满了这些单词,所以我想找到一种方法来消除这种失真

让我举一个例子:

text <- c("Stackoverflow is a great website where you can find great and very skilled people who are so kind to solve your coding problems. In the short-term is a very good thing because you can speed up your research, in the long-term is better if you learn how to code on your own. Let me add more non-sense to make my point. The growth-friendly composition of public finance is a good thing.")

ch_vector <- lemmatize_strings(text)

相反,我想要这个:

"Stackoverflow be a great website where you can find great and very skill people who be so kind to solve your code problem. In the **short-term** be a very good thing because you can speed up your research, in the **long-term** be good if you learn how to code on your own. Let me add much **non-sense** to make my point. The **growth-friendly** composition of public finance be a good thing."
到目前为止,我对每个感兴趣的词都是这样做的:

ch <- sub(pattern = "growth - friendly", replacement = "growth-friendly", x = ch_vector, fixed = TRUE)

ch

但是,我不确定这将如何与
textstem
包的设计用途相互作用,因此这可能满足您的需求,也可能不满足您的需求。

它工作得很好,tanks!我自己也试过了,但使用了下面的代码
sub(“-”,“-”,x)
,但它不起作用。然而,使用gsub可以很好地工作!再次感谢
ch <- sub(pattern = "growth - friendly", replacement = "growth-friendly", x = ch_vector, fixed = TRUE)

x <- "Stackoverflow be a great website where you can find great and very skill people who be so kind to solve your code problem. In the **short - term** be a very good thing because you can speed up your research, in the **long - term** be good if you learn how to code on your own. Let me add much **non - sense** to make my point. The **growth - friendly** composition of public finance be a good thing."
gsub(" - ","-",x)

# [1] "Stackoverflow be a great website where you can find great and very skill people
# who be so kind to solve your code problem. In the **short-term** be a very good thing
# because you can speed up your research, in the **long-term** be good if you learn how to
# code on your own. Let me add much **non-sense** to make my point. The 
# **growth-friendly** composition of public finance be a good thing."