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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to