用R语句到单词表 [英] Sentence to Word Table with R

查看:147
本文介绍了用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,

这就是我想要的,

我的意思是不重复.

推荐答案

原始中的解决方案,

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)

或者,

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

谢谢.

这篇关于用R语句到单词表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆