0

我想在我的单词向量中获得一个层次结构,如示例中所示:

# Start (in reality these will not be right next to each other)

words <- c("hello-world", "hello", "string", "sub-string", "custom-fields", 
           "custom", "hi-hat", "hat") 

# Result

highlevel <- c("hello-world", "sub-string", "custom-fields", "hi-hat")
lowerlevel <- c("hello", "string", "custom", "hat") 

实际上,我将面对大数据,并正在寻找一种有效的方法来对这些数据进行分组。如果可能的话,我也希望它们以某种方式联系起来。目标是先搜索较高级别的词,当找不到时,再寻找较低级别的词。

想法?

4

1 回答 1

2
g <- grep('[-.[:digit:]]', words) # give indices of matches.

highlevel <- words[g]
lowlevel <- words[-g]
于 2013-09-09T20:41:40.737 回答