I am a Stata user and I have to use R for a project. I want to repeat a line of code for different values. In other words, I want to avoid repeating these lines 15 times:
M20<-as.data.frame(cbind(c(1:20),exclusivity(model20), semanticCoherence(model=model20, docs), "Mod20"))
M21<-as.data.frame(cbind(c(1:21),exclusivity(model21), semanticCoherence(model=model21, docs), "Mod21"))
If I follow the logic of Stata, I would write something like this:
forvalues i=20(1)35 {
M`i'<- as.data.frame(cbind(c(1:`i'),exclusivity(model`i'), semanticCoherence(model=model`i', docs), "Mod`i'"))
}
and Stata would understand that `i' should change each time, whether it's a number or part of the name of an object.
I can't figure out how I can replicate the same loop in R.
I appreciate your help
p.s. someone said my question is the same as this one. I don't see the similarity! How to apply a function to a certain column for all the data frames in environment in R