Re: [R] How to create as.numeric.xxx

2012-11-16 Thread Prof Brian Ripley
On 16/11/2012 10:01, Marc Girondot wrote: I would like to create a function to convert data based on a class using as.numeric Similarly, using a plot, I do: plot.essai <- function(x, ...) {return(x*2)} d <- 10 class(d) <- "essai" plot(d) It works: [1] 20 attr(,"class") [1] "essai" Now same w

Re: [R] How to create as.numeric.xxx

2012-11-16 Thread Rui Barradas
Hello, Actually, it's working as expected. 'numeric' is a class and the function as.numeric() is doing what it should: as.numeric.essai <- function(x, ...) {return(x*2)} d2 <- as.numeric(d) class(d2) [1] "numeric" Maybe you want an as.essai function. as.essai <- function(x, ...) {x <- as.num