简体   繁体   English

用 R 语句到 Word 表

[英]Sentence to Word Table with R

I have some sentences, from the sentences I want to separate the words to get row vector each.我有一些句子,从句子中我想将单词分开以获得每个行向量。 But the words are repeating to match with the largest sentence's row vector that I do not want.但是这些词正在重复以与我不想要的最大句子的行向量相匹配。 I want no matter how large the sentence is, the row vector of each of the sentences will only be the words one time.我想无论句子有多大,每个句子的行向量都只会是单词一次。

sentence <- c("case sweden", "meeting minutes ht board meeting st march now also attachment added agenda today s board meeting", "draft meeting minutes board meeting final meeting minutes ht board meeting rd april")
sentence <- cbind(sentence)
word_table <- do.call(rbind, strsplit(as.character(sentence), " "))
test <- cbind(sentence, word_table)

This is what I get now,这就是我现在得到的在此处输入图片说明

And this is what I want,而这正是我想要的在此处输入图片说明

I mean no-repeating .我的意思是不重复

The Solution from rawr ,来自rawr的解决方案,

sentence <- c("case sweden", "meeting minutes ht board meeting st march now also attachment added agenda today s board meeting", "draft meeting minutes board meeting final meeting minutes ht board meeting rd april")
dd <- read.table(text = paste(sentence, collapse = '\n'), fill = TRUE)
test <- cbind(sentence, dd)

Or,或者,

cc <- read.table(text = paste(gsub('\n', '', sentence), collapse = '\n'), fill = TRUE)
test1 <- cbind(sentence, cc)

Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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