[R] How to create as.numeric.xxx
Marc Girondot
marc_grt at yahoo.fr
Fri Nov 16 11:01:48 CET 2012
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 with as.numeric:
as.numeric.essai <- function(x, ...) {return(x*2)}
as.numeric(d)
It does not work:
[1] 10
Is it possible ?
Thanks a lot
Marc Girondot
More information about the R-help
mailing list