所以有一个环境,我把 data.frame 放进去
dtm <- DocumentTermMatrix(corpus)
termCount = c(".94", ".96", ".98" ,".99")
freqMatrix <- new.env()
spam <- new.env()
for (v in termCount){
# Remove sparse terms to get a managable number of terms.
dtmEnv[[v]] <- removeSparseTerms(dtm, as.numeric(v))
# Convert the document term matrix to a standard matrix.
freqMatrix[[v]] <- as.data.frame( as.matrix(dtmEnv[[v]]))
# Normalize the frequency matrix: 0 if absent, 1 if present.
spam[[v]] <- (freqMatrix[[v]] > 0) + 0 # Add 0 to convert from logical to int.
}
然后,当我尝试从我的数据框中获取切片时,我得到一个错误
for (v in termCount){
trainData <- (spam[[v]])[folds$subsets[folds$which != i], ]
testData <- (spam[[v]])[folds$subsets[folds$which == i], ]
# ... more stuff hear ...
}
spam[[v]] 中的错误(来自 #8):子集环境的参数错误
打印得到的精度。
我究竟做错了什么?是否有一种更简洁的方法可以对 termCount 中的不同值进行这种迭代?