[R] How to figure the type of a variable?
Duncan Murdoch
murdoch at stats.uwo.ca
Sun Sep 6 18:43:49 CEST 2009
On 06/09/2009 12:33 PM, Peng Yu wrote:
> Hi,
>
> I want to know what is there returned values of 'lm'. 'class' and 'lm'
> does not show that the returned value has the variable coefficients,
> etc. I am wondering what is the command to show the detailed
> information. If possible, I aslo want the lower level information. For
> example, I want to show that 'coefficients' is a named list and it has
> 2 elements.
Try the str() function, it shows a summary of the structure of an object.
Duncan Murdoch
>
> Regards,
> Peng
>
>> x=1:10
>> y=1:10
>> r=lm(x~y)
>> class(r)
> [1] "lm"
>> mode(r)
> [1] "list"
>> r
>
> Call:
> lm(formula = x ~ y)
>
> Coefficients:
> (Intercept) y
> 1.123e-15 1.000e+00
>
>> r$coefficients[1]
> (Intercept)
> 1.123467e-15
>> r$coefficients[[1]]
> [1] 1.123467e-15
>> r$coefficients[2]
> y
> 1
>> r$coefficients[[2]]
> [1] 1
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list