#! Usr/bin/perl
Use Statistics: R;
# --- New Function
My $ r = statistics: R-> New ();
# --- Send and read Functions
$ R-> send (qq 'a = C (1, 2, 3, 4); B = mean (a); \ n C = SQRT (B); print (c )');
My $ result = $ R-> read;
Print $ result, "\ n ";
# --- Convert the value format
$ Result = ~ S/\ [\ D \] \ s + (\ D +)/$1/g;
Print $ result + 2;
Print "\ n ";
# Set, get, run
My $ value = 12;
$ R-> set ('x', $ value );
My $ key = $ R-> get ('x ');
Print $ key, "\ n ";
$ R-> Run (q'y = x + 4 ');
My $ DATA = $ R-> get ('y ');
Print $ data;
My @ str1 = (5, 6, 7, 10 );
My @ str2 = (1, 7, 3, 5 );
$ R-> set ('x1 ', \ @ str1 );
$ R-> set ('x2 ', \ @ str2 );
$ R-> Run (q'cov <-Cov (x1, x2 )');
$ R-> Run (q'x22 <-X1 ^ 2 ');
My $ cov = $ R-> get ('cov ');
My $ x22 = $ R-> get ('x22 ');
Print $ cov, "\ n ";
Print "@ $ x22 \ n ";
# Perform a simple matrix operation
My @ str11 = (5, 6, 7, 10 );
My @ str22 = (1, 7, 3, 5 );
$ R-> set ('x', \ @ str11 );
$ R-> set ('y', \ @ str22 );
$ R-> Run (q'z = C (x, y )');
My $ UU = $ R-> get ('Z ');
Print scalar @ $ Uu, "\ n ";
Foreach my $ SS (@ $ UU ){
Print "$ SS \ n ";
}
# Make a simple kmeans Algorithm
$ R-> Run (q'library (class )');
$ R-> Run (q'x =; y = kmeans (x, 4); s = y $ cluster ');
My $ result1 = $ R-> get ('s ');
Print "@ $ result1 \ n ";
Foreach my $ key (@ $ result1 ){
Print $ key, "\ n ";
}