Rmath | Statistical Distributions from R
kandi X-RAY | Rmath Summary
kandi X-RAY | Rmath Summary
The Rmath library from R. This was modified from the RMath repository from Julia-Lang to obviate the need to set MATHLIB_STANDALONE and to generate a static library by default.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Rmath
Rmath Key Features
Rmath Examples and Code Snippets
Community Discussions
Trending Discussions on Rmath
QUESTION
I am running R 4.0.4 (Lost Library Book) in Rstudio 1.4.1106 under Ubuntu 18.04.5 LTS. I am new to R and I ultimately want to install the following packages:
...ANSWER
Answered 2021-Mar-09 at 01:29@user20650's suggestion solved the issue.
- Go to here and follow the instructions to add a Personal Package Archive (PPA) to your system.
- Use
sudo apt install r-cran-magicaxis
to install the packagemagicaxis
, or replacemagicaxis
with the desired package. The form of the package name is in all small letters.
QUESTION
I'm trying to draw a random sample from 1,2,3,4 under a given probability vector of length four in C, with the help of Rmath.h. I found this line of code could do this for me.
inline void rmultinom(int n, double* prob, int k, int* rn)
For example, I can write it to draw one random sample.
double p[4]={.1, .2, .3, .2};
rmultinom(1, p, 1, int* rn)
However, I'm lost what this 4th argument should be. In R, the rmultinom function only requires the first three arguments. Another question is what is returned from this function. Is there any convenient way for it to return with one of 1, 2, 3, 4?
...ANSWER
Answered 2020-Aug-12 at 06:52Here's a simple example
QUESTION
currently I am introducing myself to C to extend my R-functions. I wrote a function in C for some computations and they work fine. But as soon as I write a wrapper in R itself there seems to be some mistake. Consider my C-function as "colV" and "abc" as some arbitrary matrix.
The statement (R) .Call("colV", abc, ncol(abc), nrow(abc))
works totally fine (everytime, no matter how often I use it), whereas
ANSWER
Answered 2020-Mar-21 at 13:15EDIT: As said in a comment, this (below) works, however for another different c-Function the same problem occurs. Using .Call directly delivers expected result, whereas putting .Call in a wrapper comes up with something wrong. I still haven't found out why.
I found the solution to the problem now, however I don't understand why it is the solution. If anybody can explain this, feel free to do so!
Changing the calculation of the colMean part in the loop was changing everything:
QUESTION
I have a problem where I need to numerically integrate a univariate function with multiple extra inputs other than the variable that's being integrated over. The integration is from zero to infinity.
I said without extra parameters because I already defined a class with the extra parameters being the private member variables. And then the operator functor is defined to accept just the integration variable (hence, univariate). With this class, I want to use the GSL numerical integration library (gsl/gsl_integration.h) to do the integration. Is there a way to define a member function for this integration inside the class using GSL?
...ANSWER
Answered 2020-Jan-28 at 14:46I found a solution for this. The solution was to move away from GSL and use the Boost library. There is a Gauss-Kronrod quadrature function in Boost math library so this will do the job.
QUESTION
I have a large dataframe as below:
df1 (sample data)
...ANSWER
Answered 2018-Nov-08 at 12:33Use nested list comprehension with join
and split
:
Notice:
Assuming no null/ NaNs values.
QUESTION
I want to use the cpp functions of an R-package (AlgDesign - https://github.com/jvbraun/AlgDesign/tree/master/src) within my own cpp project.
My usual IDE is Visual Studio 2015. I have found this related post Building R packages (C API) with Visual Studio (and How do I compile a dll with R and RCPP?) So I installed MinGW and CodeBlocks IDE on my Windows 8.1 and retry. I added the "Rdir/include" path to the "Project build options->search directories->compiler" within CodeBlocks.
But I still get "undefined reference _GetRNGstate" which is equivalent to MSVC "unresolved external symbol _GetRNGstate". So i guess the issue is a missing lib like the original questioner already mentioned. But i could not figure out which one either. There is no .lib file in my R-install dir.
Furthermore is not my intend to use Rcpp or to build an own R-package, I just want to access the SEXP FederovOpt(..args) function within my own cpp-project´
Edit: Lets say i want to transfer the AlgDesign src file function by function into an empty project. At some point I'll reach this:
...ANSWER
Answered 2018-Aug-29 at 17:04I see two possible approaches:
- Embed an R interpreter into your application, e.g. using the
Rinside
package. Then you can call the R function that wraps aroundFederovOpt
. - The
FederovOpt
function wraps around some normal C functions that do the actual work. It’s main task is to interface these C functions with R. If you are not using R otherwise you could also extract these C functions and use them directly.
Which solution to use? If you need other R functionality, 1. might be easier. Have a look at the examples that come with Rinside. You probably have to stick with mingw, preferably from Rtools. If this is the only R functionality you need, 2. Is probably the way to go. If you make the code independent of R, you can use VS. There are examples where something similar was done, e.g. https://github.com/zhanxw/libMvtnorm. In both cases you have to abide to the GPL.
To make option two more explicit I made a simple test:
- Download
FederovOpt.c
andwheeler.h
. - Remove all
#include
s of R specific headers. - Add
#include
and#define
s forTRUE
andFALSE
. - Remove the R specific functions
ProgAlloc
,ProgDealloc
andFederovOpt
- Remove R specific function calls
R_CheckUserInterrupt()
,GetRNGstate()
andPutRNGstate()
. - Replace
unif_rand()
withrand() / (RAND_MAX + 1.0)
.
The resulting file can be compiled with gcc
without error or warning. One could even link it without the need for R specific libraries when one adds a main()
. In there you would allocate memory, call FederovOptimize
and free the memory again.
BTW, the RNG is of course much worse than R's RNG, but might be sufficient for this task. With C++11 you have of course better possibilities available.
QUESTION
I am wanting to use the dbeta function in the Rmath package of Julia with the following call:
...ANSWER
Answered 2018-Aug-04 at 07:07Rmath version 0.4.0 has the following methods for dbeta
:
QUESTION
I experience a crash of R if I call a C function (from R) repeatedly.
I am a newbie in writing C functions and I think that the issue of a R crash I am experiencing is the memory allocation in C. I know that one can free the memory in C, but I cant figure out how exactly and on which parameters. Can anybody help me out here?
I will post a working example here and my issue/question again at the end.
This is the C-Code (credits: the code is based on the code of the mcplr package by Marteen Speeklenbrink (https://github.com/rforge/mcplr).
...ANSWER
Answered 2018-Feb-17 at 23:43The problem is that you are defining the vector val
twice:
QUESTION
I want to process two raster images (Ra and Rb), with Ra is the pixel value itself and Rb the values of its neighbors. taking sum as an example, assuming an 3*3 neighbors, for each pixel in Ra I will add its value to values of the neighbor pixels in Rb, an finally i will get another image.
The R raster package provides a focal function, which works only on one image input, i tried to modify the C++ code (enter link description here) to accept two image input using Rcpp. The modified code works well if there is no missing values in the input image of Rb. However, R always aborts if there is NA in Rb. Specifically, abort at the second or third test. it may be similar to this post. however, it did not crash if no NA in the input Rb. It seems i did not handle NA correctly. I do not have deep knowledge on C++, Can somebody help me check this?
here is my cpp file:
...ANSWER
Answered 2017-Jun-13 at 06:04First of all, you should only be using the #include
statement. The other headers you are adding are not needed or already included within Rcpp.h
.
Secondly, the correct way to reference the NA
value for NumericVector
s within Rcpp is to use the NA_REAL
not R's R_NaReal
.
Thirdly, you have an out of bounds error. If you switch the parentheses from []
to ()
you have bounds detection. The error on Rcpp 0.12.11 is:
"Index out of bounds: [index=3; extent=3]."
As a result, this is creating an "Undefined Behavior" (UB) that triggers the crash of RStudio.
The problematic line is:
QUESTION
UPDATE Previous example is complicated, hence please allow me to use a simpler example as shown below:
Here is the Rcpp code:
...ANSWER
Answered 2017-May-22 at 11:59I think I fix the Rcpp code, so right now both Rcpp and R code produce the same results when the results are very small values. The solution is shown as below:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Rmath
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page