How to call logarithm function of a vector of Rcpp in Rstudio

I'm using Rstudio and i want to use the logarithm version of Rcpp to compute the logarithm of a vector.

I have search on the internet and it seems to me that there exists a function called Rcpp::log()

However, when i import Rcpp into R and use Rstudio to call that function, it tells me that the function "log" does not exist in Rcpp.

I would like to ask if there is indeed the function Rcpp::log() ? If there is one, could you please tell me how to use it from Rstudio ? (otherwise, I think i have to write a new logarithm function myself).

Thank you very much!

Upvotes: 0

Views: 302

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368261

Create a vector, call log() on it, return the result:

> Rcpp::cppFunction("NumericVector logvec(NumericVector v) { return log(v); }")
> logvec(seq(1.0, 2.0, by=0.25))
[1] 0.000000 0.223144 0.405465 0.559616 0.693147
>

You can read the introduction to Rcpp which ships with the package too.

Upvotes: 1

Related Questions