How to print textual representation of single documents stored in a tm corpus in R?

和自甴很熟 提交于 2019-12-11 15:25:23

问题


I was using {tm} package and then generated a corpus using

corpus = Corpus(VectorSource(sample.words))

then I want to check the content in corpus ,but it print this instead of its texts:

> corpus
<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 3933

Now I have found some methods to look into corpus,then I started wondering what exactly R print when an object was typed in ?

> class(corpus)
[1] "VCorpus" "Corpus" 
> typeof(corpus)
[1] "list"

Why it didn`t like other ordinary lists ,printing its columns and rows?Does this has something to do whit the class attribute?

I`m new in R and not familiar with some basic concepts, thanks for your patience!


回答1:


The introduction document to the tm package says that you can use , say, writeLines(as.character(mycorpus[[4]])) to get a textual representation of document 4.

You can also use content(myCorpus[[23]]).

To read the intro document, enter browseVignettes() on your R prompt and the search for it on the browser window that will have opened.



来源:https://stackoverflow.com/questions/34236346/how-to-print-textual-representation-of-single-documents-stored-in-a-tm-corpus-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!