Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

[R] class<- vs. as()

stefan albrecht

2005-07-11

Replies:





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@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
©2008 r-help.com - Jax Systems, LLC, U.S.A.