I am trying to use the stemming function suggested in the corpus package stemming vignette here https://cran.r-project.org/web/packages/corpus/vignettes/stemmer.html
but when I try to run the function on the entire column it seems to just be repeating the result for the first row down the rest of the rows. I'm guessing this has to do with the [[1]] within the following function. I'm guessing the solution is something along the lines of "for i in x" but I'm not familiar enough with writing functions to know how to solve this.
df <- data.frame(x = 1:7, y= c("love", "lover", "lovely", "base", "snoop", "dawg", "pound"), stringsAsFactors=FALSE)
stem_hunspell <- function(term) {
# look up the term in the dictionary
stems <- hunspell::hunspell_stem(term)[[1]]
if (length(stems) == 0) { # if there are no stems, use the original term
stem <- term
} else { # if there are multiple stems, use the last one
stem <- stems[[length(stems)]]
}
stem
}
df[3] <- stem_hunspell(df$y)