Reputation: 25
I'm very new to R and am working on a text mining project. I have all the analysis working however when I convert the Term-Document Matrix back to a data frame it fills the console with the content..
The code I'm using for this is:
TDM.frame <- data.frame(inspect(Words.TDM))
The frame has 9k objects in it so I won't paste that here too but you can imagine what the console looks like when it dumps the whole content out ^^
I've tried using invisible() but that doesn't change anything. I hope someone can tell me what I'm doing wrong, or offer a solution!
Thanks!
Upvotes: 1
Views: 1751
Reputation: 263301
This is what inspect
does (at least in the case where it is given a TDM):
> tm:::inspect.TermDocumentMatrix
function (x)
{
print(x)
cat("\n")
print(as.matrix(x))
}
<environment: namespace:tm>
So you want the object that is returned which is just as.matrix(tdm)
and you do not want the printing side-effect. So you should just do this instead:
TDM.frame <- data.frame(as.matrix(Words.TDM))
Upvotes: 2
Reputation: 3764
Try
TDM.frame <- data.frame(inspect(Words.TDM))
head(TDM.frame)
Or, you can use dplyr
library(dplyr)
TDM.frame <- tbl_df(TDM.frame)
Upvotes: 0
Reputation: 3688
Is the inspect()
within data.frame()
really necessary? Can you perhaps just convert the TDM to a matrix, since it seems this is what you are trying to achieve? If necessary, you can then convert the matrix to a data frame.
as.matrix(Words.TDM)
Upvotes: 2