Error in converting into Boolean matrix for social network analysis in chapter 11

posted Aug 6, 2014, 1:26 PM by Yanchang Zhao

Q: At the begining of Chapter 11 social network analysis, the
> # change it to a Boolean matrix
> termDocMatrix[termDocMatrix>=1] <- 1

produced the error '[<-. simple_sparse_array´(as.simple_sparse_array(x),…, value= value): Only numeric subscripting is implemented.

A: The "termDocMatrix" is a normal matrix, not a term-document matrix created with package tm. Sorry for the misleading statement at the beginning for section 11.1 saying that "termDocMatrix" is "a term-document matrix".

Referring to section 10.7, "myTdm2" is a term-document matrix, and then it is converted into a normal matrix "m2" with as.matrix(). "termDocMatrix" is a copy of "m2", which is used as input in section 11.1 for social network analysis.
m2 <- as.matrix(myTdm2)

Therefore, to use your own data of class term-document matrix, you need to convert it with as.matrix() first, before running code for social network analysis in chapter 11.
yourMatrix <- as.matrix(yourTermDocMatrix)