Re: [R] class<- vs. as()

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Tue 12 Jul 2005 - 00:30:52 EST

          What do you want? Consider the following:

 > v <- matrix(1:9, 3)
 > class(v[1,1])
[1] "integer"
 > class(as.vector(v))
[1] "integer"

 > v2 <- v
 > dim(v2) <- NULL
 > class(v2)

[1] "integer"

          spencer graves

stefan.albrecht@allianz.com wrote:

>
>
>
> 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
-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves@pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915

______________________________________________
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 Tue Jul 12 00:38:31 2005

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