So have an an env that I put data.frame in
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.
}
Then however when I try taking slices from my data frame I get an error
for (v in termCount){
trainData <- (spam[[v]])[folds$subsets[folds$which != i], ]
testData <- (spam[[v]])[folds$subsets[folds$which == i], ]
# ... more stuff hear ...
}
Error in spam[[v]] (from #8) : wrong arguments for subsetting an environment
Print the resulting accuracies.
What am I doing wrong? Is there a cleaner way of doing such an iteration for different values in termCount?