First: The basic course of the R language:
Https://www.yiibai.com/r/r_environment_setup.html
Download the installation package for the R language: HTTPS://CRAN.R-PROJECT.ORG/BIN/WINDOWS/BASE/OLD/3.4.1/
NEW: vs Engineering Console
Add NuGet Package: r.net
Add test code:
static void Main (string[] args) {rengine.setenvironmentvariables (); There is several options to initialize the engine, but by default the following suffice:rengine engine = R Engine.getinstance (); The. NET Framework array to R vector. Numericvector group1 = engine. Createnumericvector (new double[] {30.02, 29.99, 30.11, 29.97, 30.01, 29.99}); Engine. Setsymbol ("Group1", group1); Direct parsing from R script. Numericvector group2 = engine. Evaluate ("Group2 <-C (29.89, 29.93, 29.72, 29.98, 30.02, 29.98)"). Asnumeric (); Test difference of mean and get the p-value. Genericvector TestResult = engine. Evaluate ("T.test (group1, Group2)"). Aslist (); Double p = testresult["P.value"]. Asnumeric (). First (); Console.WriteLine ("Group1: [{0}]", String. Join (",", group1)); Console.WriteLine ("Group2: [{0}]", String. Join (",", group2)); COnsole. WriteLine ("P-value = {0:0.000}", P); You should always dispose of the rengine properly. After disposing of the engine, you cannot reinitialize nor reuse it engine. Dispose (); Console.readkey (); }
Operation Result:
Introduction to R language and. NET Integration development