[R] unclass

Spencer Graves spencer.graves at pdf.com
Sat Aug 16 17:23:32 CEST 2003


I found an answer in "?unclass" and a minor difference between R 1.7.1 
and S-Plus 6.1.2:

First ?unclass in R 1.7.1 under Windows 2000:

      Many R objects have a `class' attribute, a character vector giving
      the names of the classes which the object ``inherits'' from. If
      the object does not have a class attribute, it has an implicit
      class, `"matrix"', `"array"' or the result of `mode(x)'.
...
      The function `class' prints the vector of names of classes an
      object inherits from.
...
      `unclass' returns (a copy of) its argument with its class
      attribute removed.

	  Thus, "incidencia <- unclass(incidencia)" removed the class attribute 
from "incidencia".  Then consistent with the documentation, 
"class(incidencia)" has an implicit class "array";  if it were not a 
matrix or array, then "class(incidencia)" would have returned the result 
of mode(x).

Now, a trivial comparison between R 1.7.1 and S-Plus 6.1.2:

##R 1.7.1
 > tst <- 2
 > class(tst)
[1] "numeric"
 > Tst <- unclass(tst)
 > class(Tst)
[1] "numeric"
 > mode(Tst)
[1] "numeric"

## Same thing in S-Plus 6.1.2:
 > tst <- 2
 > class(tst)
[1] "integer"
 > Tst <- unclass(tst)
 > class(Tst)
[1] "integer"
 > mode(Tst)
[1] "numeric"

Note that "tst" and "Tst" have class and mode "numeric" in R 1.7.1 but 
class "integer" and mode "numeric" in S-Plus 6.1.2.

hope this helps.  spencer graves

kjetil brinchmann halvorsen wrote:
> Have I been sleeping in class?
> 
> rw1071 from CRAN, windows XP
> 
> incidencia is made by a call to tapply
> 
> 
>>class(incidencia)
> 
> [1] "array"
> 
>>incidencia <- unclass(incidencia)
>>class(incidencia)
> 
> [1] "array"
> 
> 
> Kjetil Halvorsen
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list