Re: [R] unclass

About this list Date view Thread view Subject view Author view Attachment view

From: Spencer Graves (spencer.graves@pdf.com)
Date: Sun 17 Aug 2003 - 01:23:32 EST


Message-id: <3F3E4C74.8080006@pdf.com>

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@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 01 Jan 2004 - 09:19:48 EST