Here I rewrite your code using the vectorize version of SnowballStemmer
. No need to use for.
library(plyr)
stemMAP<-function(text){
flatText <- unlist(strsplit(text," "))
## here I use the vectorize version
wordStem <- as.character(SnowballStemmer(flatText))
hh <- data.frame(ff = flatText,sn = wordStem)
## I use plyr to transform the result to a list
## dlply : data.frame to list apply
## we group the hh by the column sn , and a apply the
## function as.character(x$ff) to each group( x here is subset data.fame)
stemList <- dlply(hh,.(sn),function(x) as.character(x$ff))
stemList
}
stemList
$I
[1] "I"
$a
[1] "a"
$activ
[1] "active" "activates" "activation"
$and
[1] "and" "and"
$be
[1] "being"