0

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

  • 1
    I agree with OP, it is not a duplicate question. Although there are similarities, the solution required here is different from that of the proposed duplicate -- or this problem should be reworked quite a lot to use the same solution.... – MrGumble Oct 25 '21 at 08:32
  • Thanks @MrGrumble. Do you know how I can report this guy who closed my post and reopen my question? – Monica Muller Oct 25 '21 at 08:42
  • 1
    You cannot report the guy who marked it as duplicate; I have flagged the question to be reopened and it is now waiting in a review queue for somebody else to weigh in their consideration. – MrGumble Oct 25 '21 at 08:55

0 Answers0