所以有一个env我把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 ...
}
垃圾邮件[[v]]出错(来自#8):用于对环境进行子集化的错误参数
我做错了什么? 对于termCount中的不同值,是否有更简洁的方法进行此类迭代?