0

I have 5 Document Term Matrices, say, DTM1, DTM2, DTM3, DTM4, DTM5.
Now I have written a function called myBarPlot(DTM, title, color) which accepts a DocumentTermMatrix and a Title (character) to each Plot and separate color for each plot.

Now how do I pass all my DTM's as an argument in the function myBarPlot and generate barplots. I want this to happen in a loop.
Something like this.

for(i in 1:seq(DTM)) # all the DTMs that I have
  {
     myBarPlot(DTM[i], title[i], color[i])
  }

So the objective is to pass any R object as an argument in a for-loop. It could be DTM's or multiple dataframes etc.

1 Answers1

0

You can put all the matrices in a list and then iterate over the list positions or names.

dmontaner
  • 2,076
  • 1
  • 14
  • 17