[R] what.is(object)

Marc Schwartz mschwartz at medanalytics.com
Tue May 20 18:00:44 CEST 2003


>-----Original Message-----
>From: r-help-bounces at stat.math.ethz.ch 
>[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Welch, Ivo
>Sent: Tuesday, May 20, 2003 10:43 AM
>To: r-help at stat.math.ethz.ch
>Subject: [R] what.is(object)
>
>
>
>hi:  still experimenting.  is there a function that tells me what an
S 
>object is, or how it is constructed?
>
>s <- cor.test ( x, y );
>
>s$estimate$name = 'correlation' ;   <-  try to rename 'cor' to 
>'correlation' fails.  obviously, name is not a part here.
>s$newfield = c("another info field", 3.2 ) ;  <- this is not
congruous
>
>so
>
>what.is(s)       #tells me that this is a class called htest
>what.is(s$statistic)    # helps me
>
>would allow me to see how things are constructed.   does S 
>contain such 
>a feature?
>
>regards,
>
>/iaw


You can use str(s) to get the internal components and values.

See ?str

Using example data from cor.test:

> x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
> y <- c( 2.6,  3.1,  2.5,  5.0,  3.6,  4.0,  5.2,  2.8,  3.8)
> s <- cor.test(x, y)
> str(s)
List of 9
 $ statistic  : Named num 1.84
  ..- attr(*, "names")= chr "t"
 $ parameter  : Named num 7
  ..- attr(*, "names")= chr "df"
 $ p.value    : num 0.108
 $ estimate   : Named num 0.571
  ..- attr(*, "names")= chr "cor"
 $ null.value : Named num 0
  ..- attr(*, "names")= chr "correlation"
 $ alternative: chr "two.sided"
 $ method     : chr "Pearson's product-moment correlation"
 $ data.name  : chr "x and y"
 $ conf.int   : atomic [1:2] -0.150  0.896
  ..- attr(*, "conf.level")= num 0.95
 - attr(*, "class")= chr "htest"


HTH,

Marc Schwartz




More information about the R-help mailing list