[R] unclass

Torsten Hothorn hothorn at ci.tuwien.ac.at
Sat Aug 16 16:56:32 CEST 2003


> 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"
> 
> 

`unclass' only removes the `class' attribute. However, arrays do not own
one (see the details in ?class) but its class is defined implicitly:

R> x <- array(rnorm(25), dim=c(5,5))
R> mode(x)
[1] "numeric"
R> class(x)
[1] "matrix"
R> attributes(x)
$dim
[1] 5 5

so nothing to remove here, in contrast to data.frames:

R> x <- as.data.frame(matrix(rnorm(25), ncol=5))
R> attributes(x)
$names
[1] "V1" "V2" "V3" "V4" "V5"

$row.names
[1] "1" "2" "3" "4" "5"

$class
[1] "data.frame"

R> unclass(x)
$V1
[1]  1.4085747  0.2405006  0.7056615 -0.4747142  0.5846174

$V2
[1]  1.06994019 -0.26797839 -0.54426997 -3.34744272  0.05473644

$V3
[1] -0.75277466  0.05542274 -1.13621279  1.06582063 -1.04080035

$V4
[1]  0.3942039867 -0.2680249001  0.0002451802 -2.4269886369  0.8719898617

$V5
[1]  1.186167  0.374248  0.832176  1.030344 -1.606450

attr(,"row.names")
[1] "1" "2" "3" "4" "5"

Best

Torsten

> 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