[R] class<- vs. as()

From: <stefan.albrecht_at_allianz.com>
Date: Mon 11 Jul 2005 - 22:56:46 EST

Dear all,

I would appreciate a lot, if someone could explain to me in a simple way, why the assignment class<- is not always working and one has to take as() like in the example below.

> (v <- matrix(1:9, 3))

     [,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9

> class(v)
[1] "matrix"

> class(v) <- "integer"
> class(v)
[1] "matrix"

> v

     [,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9

> (vi <- as(v, "integer"))
[1] 1 2 3 4 5 6 7 8 9
> class(vi)
[1] "integer"

With many thanks,

Stefan

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 11 23:04:25 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:28 EST