Re: [R] $

From: Gavin Simpson <>
Date: Wed 21 Jun 2006 - 03:32:38 EST

On Tue, 2006-06-20 at 12:03 -0500, Davis, Jacob B. wrote:
> Thanks for humbling yourself to my level and not answering my question.
> If object is user defined is:
> object$df.residual
> the same thing as
> df.residual(object)


In this case, yes they are the same, but don't think that if you had object$foo that you could do foo(object) and get anything useful. Most of the time you can't and R will throw an error.

df.residual() is an extractor function and these are generally preferred over extracting the component of the list directly using the $ notation. Other extractors include coef(), residuals(), fitted() etc.

"$" _is_ used to extract components from lists, and can be used on data frames as these are just a special type of list.

Look at this example:

y <- runif(100)
x <- rnorm(100)
mod <- lm(y ~ x)

If we look at the structure of the lm object, we see many components:


There is a model component, which you could extract using


but if you try


you'll get an error about not being able to find function "model".

Hopefully that explains things a little.

Gav mailing list PLEASE do read the posting guide! Received on Wed Jun 21 03:44:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 21 Jun 2006 - 04:12:01 EST.

Mailing list information is available at Please read the posting guide before posting to the list.