0

I have a problem, I would like to get different values or data frames out of an ancova loop. But I am new to R so my original approach does not work. Can someone help me?

for (u in 1:19) {
  if (u %in% Branchendaten129$Branche){
    paste0("dataStressKlimaSWK",label[u],sep = "") <- aov(Stress  ~ Klima*SWK, data=subset(Branchendaten129, Branche == label[u]))
  }else {NULL}
}

This is where I'm at... But I don't know why this approach does not get me the specific data out of my Dataframe. It is probably some problem with my Loop.

Thank you for your help. It is appreciated.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
severin
  • 111
  • 1
  • 1
  • 6
  • 1
    Welcome to SO! Please take [the tour](https://stackoverflow.com/tour) and create a minimal reproducible example. Read [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for a reference. – markus Jan 31 '19 at 18:31

1 Answers1

1

Try to use a list.

list_results <- list()

Then, in your loop, you can save each result in a specific position::

for (u in 1:19) {
  if (u %in% Branchendaten129$Branche){
    list_results[label[u]] <- aov(Stress  ~ Klima*SWK, data=subset(Branchendaten129, Branche == label[u]))
  }else {NULL}
}
Douglas Mesquita
  • 1,011
  • 7
  • 12