Re: [R] Annoyance in as.numeric

2008-06-16 Thread Gavin Simpson
On Mon, 2008-06-16 at 14:50 -0700, Taylor, Z Todd wrote: > I generally do something like > > storage.mode(my.matrix) <- "double" Ahh, that's what I was missing; I was side tracked by working out why I couldn't write an S3 method for as.double for matrices, and missed the proper solution in th

Re: [R] Annoyance in as.numeric

2008-06-16 Thread markleeds
thanks for your correction Gavin. i read ?data.matrix and neglected to pay attention to the last line of the description: "Factors and ordered factors are replaced by their internal codes". On Mon, Jun 16, 2008 at 5:30 PM, Gavin Simpson wrote: On Mon, 2008-06-16 at 15:35 -0500, [EMAIL PR

Re: [R] Annoyance in as.numeric

2008-06-16 Thread Taylor, Z Todd
une 16, 2008 2:31 PM > To: [EMAIL PROTECTED] > Cc: r-help@r-project.org > Subject: Re: [R] Annoyance in as.numeric > > On Mon, 2008-06-16 at 15:35 -0500, [EMAIL PROTECTED] wrote: > > hi: you can do below but i don't know if it's worth it ? > > > > newx <-

Re: [R] Annoyance in as.numeric

2008-06-16 Thread Bert Gunter
On Mon, Jun 16, 2008 at 4:22 PM, Alberto Monteiro wrote: > Why does as.numeric convert matrices and arrays to vectors? > Because that's what it's documented to do! " as.numeric is a generic function, but S3 methods must be written for as.double. It is identical to as.double (and as.real). " A

Re: [R] Annoyance in as.numeric

2008-06-16 Thread Gavin Simpson
On Mon, 2008-06-16 at 15:35 -0500, [EMAIL PROTECTED] wrote: > hi: you can do below but i don't know if it's worth it ? > > newx <- data.matrix(data.frame(x)) > print(newx) That doesn't work Mark: > str(data.frame(x)) 'data.frame': 2 obs. of 2 variables: $ X1: Factor w/ 2 levels "1","2": 1 2

Re: [R] Annoyance in as.numeric

2008-06-16 Thread markleeds
hi: you can do below but i don't know if it's worth it ? newx <- data.matrix(data.frame(x)) print(newx) On Mon, Jun 16, 2008 at 4:22 PM, Alberto Monteiro wrote: Why does as.numeric convert matrices and arrays to vectors? as.numeric(matrix(c("1", "2", "3", "4"), 2, 2)) [1] 1 2 3 4 I could

[R] Annoyance in as.numeric

2008-06-16 Thread Alberto Monteiro
Why does as.numeric convert matrices and arrays to vectors? as.numeric(matrix(c("1", "2", "3", "4"), 2, 2)) [1] 1 2 3 4 I could only figure out ugly ways to bypass this, like: x <- matrix(c("1", "2", "3", "4"), 2, 2) array(as.numeric(x), dim = dim(x), dimnames = dimnames(x)) Alberto Monteiro _