r - 比这更简单的代码? - rgraphviz情节

时间:2017-02-19 02:22:35

标签: r optimization plot reshape

我没有看到从Rgraphviz相关图中排除非连接词的直接方法。我开发了一种复杂的方法来删除不在图中的术语。 (我是r的新手。)Rgraphviz实际上是否有这个选项,和/或是否有更少的复杂代码来获得所需的术语子集?

terms1=findFreqTerms(dtm, lowfreq=30)
# Find the subset of terms1 where every term in terms1 has a 
# correlation of at least 0.7 with at least one other term in terms1, 
# as they occur in the dtm.
c1 = cor(as.matrix(dtm))
c2 = c1[terms1,terms1]
c2[c2 == 1] <- NA 
c2[abs(c2) < 0.7] <- NA 
library(reshape)
c2 <- na.omit(melt(c2)) 
c2 = as.data.frame.array(c2)
c2 = unique(c2[,2])
# Rgraphviz must be loaded.
plot(dtm, terms=c2, corThreshold=0.7)

此代码存在潜在缺陷 - 如果两个术语碰巧具有1.0的相关性。该行用于删除与自身的术语相关性。

0 个答案:

没有答案
相关问题