Is approx () used for complex numbers?

I did the following experiment, since there is no description of complex data on the approx help page:

 Rgames> zfoo [1] 1+ 6i 2+ 7i 3+ 8i 4+ 9i 5+10i Rgames> approx(zfoo,n=10) $x [1] 1.000000 1.444444 1.888889 2.333333 2.777778 3.222222 3.666667 4.111111 [9] 4.555556 5.000000 $y [1] 6.000000 6.444444 6.888889 7.333333 7.777778 8.222222 8.666667 [8] 9.111111 9.555556 10.000000 

Digging in the code for approx , I found that xy.coords (also explicitly undocumented for complex data) treats parts of complex Real and Imag data as parts of x and y coordinate data. So my question is: is this intentional behavior? I am always a little paranoid depending on functionality that is not explicitly documented.

+7
source share
1 answer

It looks intentional and reliable for me, since approx() calls regularize.values() , which calls xy.coords() , which includes this code block:

 else if (is.complex(x)) { y <- Im(x) x <- Re(x) xlab <- paste0("Re(", ylab, ")") ylab <- paste0("Im(", ylab, ")") } 

after which approx() continues just as if you were passing it the numerical (real / rational) vectors x and y .

+6
source

All Articles