Hello, With this program I try to repeat analysis for different years. The results of the analysis are not printed when in the loop, except for the year sequence. What is wrong? Thanks a lot. for (i in 92:99){ cat("\n", "=============================================================\n", "YEAR =",i,"\n", "=============================================================\n" ) canos1 <- subset (canos, canos$YEAR==i) LinearModel.1 <- lm(MM_P ~ BLOC + TIL, data=canos1) summary(LinearModel.1) Anova(LinearModel.1, type="II") Anova(LinearModel.1, type="III") } -- ************************************************** Jorge Lampurlan?s Castel Departament d'Enginyeria Agroforestal Escola T?cnica Superior d'Enginyeria Agr?ria Universitat de Lleida Avinguda Rovira Roure, 191 25198-LLEIDA SPAIN Tl.: +34 973 70 25 37 Fax.:+34 073 70 26 73 e-mail: jlampur at eagrof.udl.es
If you really want the summary() etc to print to STDOUT use cat() or print(). However other ways to post-process results may be preferrable, I think about Sweave, xtable, etc. Regards Michael Jorge Lampurlanes Castel wrote:> Hello, > > With this program I try to repeat analysis for different years. The > results of the analysis are not printed when in the loop, except for the > year sequence. What is wrong? > > Thanks a lot. > > for (i in 92:99){ > cat("\n", > "=============================================================\n", > "YEAR =",i,"\n", > "=============================================================\n" > ) > canos1 <- subset (canos, canos$YEAR==i) > LinearModel.1 <- lm(MM_P ~ BLOC + TIL, data=canos1) > summary(LinearModel.1) > Anova(LinearModel.1, type="II") > Anova(LinearModel.1, type="III") > > } > >-- Michael T. Mader Institute of Stem Cell Research GSF - National Research Center for Environment and Health Ingolstaedter Landstrasse 1 D-85764 Neuherberg 0049-89-3187-3683 The limits of my language are the limits of my world. Ludwig Wittgenstein Tractatus Logico-Philosophicus 5.6, 1918
Jorge Lampurlanes Castel wrote:> Hello, > > With this program I try to repeat analysis for different years. The > results of the analysis are not printed when in the loop, except for the > year sequence. What is wrong? > > Thanks a lot. > > for (i in 92:99){ > cat("\n", > "=============================================================\n", > "YEAR =",i,"\n", > "=============================================================\n" > ) > canos1 <- subset (canos, canos$YEAR==i) > LinearModel.1 <- lm(MM_P ~ BLOC + TIL, data=canos1) > summary(LinearModel.1) > Anova(LinearModel.1, type="II") > Anova(LinearModel.1, type="III") > > }You might consider using by() rather than a loop as follows: library(car) by(canos, canos$YEAR, function(x){fm <- lm(MM_P ~ BLOC + TIL, data=x) ans <- list(summary(fm), Anova(fm, type="II"), Anova(fm, type="III")) } ) The result can be conveniently stored as a list of lists. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894