# 19     R Statistics

BI Studio integrates the R statistical analysis software can run pure R Scripts and also combines LINQ, SQL and R Engine for statistical analysis. To run R Scripts you must install the R Statistical software.

## 19.1                Native R Scripts

Nucleon BI can execute native R scripts and get the results in a Dataset including Plots. It allows reading data from Database using Data Binding technology (see Data Binding) and getting the outputs in a table object for further reporting or processing.

## 19.2                R .Net/C# Integration

R integration requires native R-DLLs installed with R environment. You need no other extra installations. R is a free software environment for statistical computing and graphics.

R-Integration can be used with the combination of SQL, LINQ and R statistical software. Using BI Studio with R combination, you can do advanced data analysis with LINQ and R Scripts.

This code example illustrates how R-Integration works.

```// .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();
```
```
```
```//Dump the Reults
```
```Output(("Group1: [{0}]", string.Join(", ", group1)));
```
```Output (("Group2: [{0}]", string.Join(", ", group2)));
```
```Output (("P-value = {0:0.000}", p));
```