Skip to content

summary() within a function

3 messages · Rodrigo Abt, Eric Lecoutre, uaca@alumni.uv.es

#
Ulisses, could you be a little more specific ?. What OS, R version and data
you are using ?

I've tested this as an example and works fine (at least for me):
x<-1:10
	y<-rnorm(10)
	s<-lm(y~x+0)
	summary(s)
}
Call:
lm(formula = y ~ x + 0)

Residuals:
    Min      1Q  Median      3Q     Max
-1.8488 -0.6693  0.2065  0.5043  1.5903

Coefficients:
  Estimate Std. Error t value Pr(>|t|)
x  0.07631    0.05400   1.413    0.191

Rodrigo Abt B.,
SII, Chile.

---

Date: Wed, 14 Jan 2004 09:24:22 +0100
From: uaca at alumni.uv.es
Subject: [R] summary() within a function
To: r-help at stat.math.ethz.ch
Message-ID: <20040114082422.GA18168 at pusa.informat.uv.es>
Content-Type: text/plain; charset=iso-8859-1

I have the following function

f <- function {

	...

	model <- lm(rttx[,1] ~ rttx[,2] + 0);
	summary(model);

	...
}

while summary(model) shows the summary if I execute the function line by
line
in the Command Line Interface, if I call f() summary is silent

how to solve it? or is there workaround?

thanks in advance

	Ulisses

                Debian GNU/Linux: a dream come true
----------------------------------------------------------------------------
-
"Computers are useless. They can only give answers."            Pablo
Picasso

--->	Visita http://www.valux.org/ para saber acerca de la	<---
--->	Asociacisn Valenciana de Usuarios de Linux		<---
#
Unless 'summary' is the last evaluated object within your function (and 
then it is the one implicitely returned by the function), you have to 
explicitely ask for printing it:


f <- function {
         ...
         model <- lm(rttx[,1] ~ rttx[,2] + 0);
         # Print summary for the model
         print(summary(model));
         ...
}
At 16:35 14/01/2004, Rodrigo Abt wrote:
--------------------------------------------------
L'erreur est certes humaine, mais un vrai d?sastre
n?cessite un ou deux ordinateurs. Citation anonyme
--------------------------------------------------
Eric Lecoutre
Informaticien/Statisticien
Institut de Statistique / UCL

TEL (+32)(0)10473050       lecoutre at stat.ucl.ac.be
URL http://www.stat.ucl.ac.be/ISpersonnel/lecoutre
#
On Wed, Jan 14, 2004 at 04:53:45PM +0100, Eric Lecoutre wrote:
Thanks for the explanation
It worked as spected

regards

	Ulisses

                Debian GNU/Linux: a dream come true
-----------------------------------------------------------------------------
"Computers are useless. They can only give answers."            Pablo Picasso

--->	Visita http://www.valux.org/ para saber acerca de la	<---
--->	Asociaci?n Valenciana de Usuarios de Linux		<---