0

I have some r code that I've used in the past to produce topic models. Everything was working fine until I updated all of my r packages in the hopes of fixing a slightly unrelated problem. Now, code which had previously worked seems to be broken and I can't figure out what to do.

I read this post and found it very helpful in setting this up originally. It describes a method of cleaning blank rows after sparse terms have been removed to set up subsequent analysis. Here is what happens when I enter the same code with my current packages:

> rowTotals <- apply(a.dtm.t, 1, sum) #Find the sum of words in each Document
> a.dtm.t.rt <- a.dtm.t[rowTotals>0]
Error in `[.simple_triplet_matrix`(a.dtm.t, rowTotals > 0) : 
  Logical vector subscripting disabled for this object.

Does anyone know how I can go about locating the problem, and roll back to a working solution? Thanks.

Community
  • 1
  • 1
beniam
  • 89
  • 1
  • 2
  • 5

2 Answers2

0

Try a.dtm.t.rt <- a.dtm.t[which(rowTotals>0)]

If that doesn't work then you need to show a reproducible example. We have no idea what anything you're doing here is.

stanekam
  • 3,906
  • 2
  • 22
  • 34
  • Thanks iShould. After some further experimenting I discovered that if I roll back my version of the r package tm to version 0.5-9.1 from the current version which is version 0.5-10 my code works again. I was able to do that using time machine on a mac. I'm sure this is not best practice but it works for me. I still don't know how to rewrite code moving forward to ensure that it works for current and future versions of the tm package, and the above solution does not work. More answers would be appreciated. – beniam Jan 31 '14 at 17:55
0

I find the same problem as yours. I use slam package to solve this issue.

library(slam)
# take tdm as a large term-document matrix
freq <- rowapply_simple_triplet_matrix(tdm,sum)

Also the colapply_simple_triplet_matrix will help to handle the sparse matrix

yufree
  • 433
  • 3
  • 9