Home > Software design >  Apply a text mining function to every data frame within a list of data frames by using a for loop?
Apply a text mining function to every data frame within a list of data frames by using a for loop?

Time:01-30

I have a list of dataframes and I would like to apply a text mining command (namely removing punctuation) to every dataframe within my list of dataframes. Since I have more than 1k dataframes/documents within my list I should do it with a for loop/apply function.

   library("tm")
    
    corpus$df_19970207 <- tm_map(corpus$df_19970207, removePunctuation)
    corpus$df_19970310 <- tm_map(corpus$df_19970310, removePunctuation)

... and so on.

corpus would be my list of data frames and df_xxx the respective data frame.

What would be the easiest way to do this? I know I did not provide a repex but I feel like my question is so trivial..

Many thanks in advance!

CodePudding user response:

We may use lapply

corpus2 <- lapply(corpus, function(x) tmp_map(x, removePunctuation))
  • Related