如何将我从R中的文本挖掘中获得的termDocumentMatrix转换为excel或CSV文件? [英] How to convert a termDocumentMatrix which I have got from text mining in R into excel or CSV file?

查看:198
本文介绍了如何将我从R中的文本挖掘中获得的termDocumentMatrix转换为excel或CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更具体.可以说我有一个带有以下元素的字符向量名称":

To be more more specific. Lets say I have a character vector "names" with the following elements:

Names[1]<-"aaron, matt, patrick",
Names[2]<-"jiah, ron, melissa, john, patrick"

依此类推...我有22956个这样的元素.我想分隔所有名称,并在excel中为它们分配一个单独的列. 我该怎么做呢?它需要文本挖掘.但是我不确定该怎么做.

and so on......I have 22956 elements like this. I want to separate all the names and assign them a separate column in excel. How do I do this? It requires text mining. But I am not sure how to do this.

谢谢.

推荐答案

我假设您有一个由逗号分隔的字符串元素列表,具有不同数量的元素.

I assume you have a list of strings elements separated by a comma, with different number of elements.

Names <- c("aaron, matt, patrick",
           "jiah, ron, melissa, john, patrick")

## get max number of elements
mm <-  mm <- max(unlist(lapply(strsplit(Names,','),length)))
## set all rows the same length
lapply(strsplit(Names,','),function(x) {length(x) <- mm;x})
## create a data frame with the data welle formatted
res <- do.call(rbind,lapply(strsplit(Names,','),function(x) {length(x) <- mm;x}))
## save the file
write.csv(res,'output.csv')

我认为您也可以使用plyr包中的rbind.fill,但是您必须将每一行强制为data.frame(一定的费用).

I think also you can use rbind.fill from plyr package, but you have to coerce each row to a data.frame( certain cost).

这篇关于如何将我从R中的文本挖掘中获得的termDocumentMatrix转换为excel或CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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