[Rcpp-devel] how to use R distributions while using RcppArmadillo
Dirk Eddelbuettel
edd at debian.org
Fri Sep 16 14:29:39 CEST 2016
On 16 September 2016 at 16:59, Amina Shahzadi wrote:
| Hello Friends
|
| I tried to find that how we can use pnorm(), dpois() etc. using arma library.
| It is easy to use using Rcpp. Would anybody help ?
Here you go:
R> library(Rcpp)
R> cppFunction("arma::vec foo() { return as<arma::vec>( rnorm(5) ); }", depends="RcppArmadillo")
R> set.seed(42); foo()
[,1]
[1,] 1.370958
[2,] -0.564698
[3,] 0.363128
[4,] 0.632863
[5,] 0.404268
R>
R> set.seed(42); rnorm(5)
[1] 1.370958 -0.564698 0.363128 0.632863 0.404268
R>
There are literally hundreds of more complex examples out there. Just search.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel
mailing list