Multiple aov outputs with titles in one text file
Hello,
I need some help on figuring out how to add titles to multiple outputs into one text file. I have tried to use the cat() and sink() function but it's not really producing the output I want. Here is an example of what I want. For example say that I have 3 linear models:
model1 --> lm(weight~variety, data=testdat)
model2 --> lm(height ~ variety, data = testdat)
model3 ---> lm(N2conc ~ variety, data =testdat)
aov(model1)
aov(model2)
aov(model3)
I want to make a text file that has a list of all the anovas with the model for each anova in a text file. I want something like this:
**Anova_output.txt**
model1 --> lm(weight~variety, data=testdat) ### I want model as the title so I can distinguish each anova data
[anova data of model 1]
model2 --> lm(height ~ variety, data = testdat)
[anova data of model 2]
model3 ---> lm(N2conc ~ variety, data =testdat)
[anova data model3]
Any guidance on this would be helpful. Thanks!
• 1,405 views
•
link
1 answer
aov already stores that information in $call, try this example:
for(i in c("cyl", "disp")){
f <- as.formula(paste("mpg", i, sep = "~"))
x <- aov(lm(f, mtcars))
x$call <- f
capture.output(x, file = "tmp_1.txt", append = i!="cyl")
}
Anova_output.txt
Call:
mpg ~ cyl
Terms:
cyl Residuals
Sum of Squares 817.7130 308.3342
Deg. of Freedom 1 30
Residual standard error: 3.205902
Estimated effects may be unbalanced
Call:
mpg ~ disp
Terms:
disp Residuals
Sum of Squares 808.8885 317.1587
Deg. of Freedom 1 30
Residual standard error: 3.251454
Estimated effects may be unbalanced
• 0 views
•
link
Log in to answer this question.
Hello
This seems to be for only one model. I was looking for something with multiple models all into one text file.