1 | rlab -- A JavaScript Scientific Library like R based on lodash and jStat
|
2 |
|
3 |
|
4 | ## install
|
5 |
|
6 | ```
|
7 | npm install rlab
|
8 | ```
|
9 |
|
10 | ## use rlab
|
11 |
|
12 | file : rtest.js
|
13 |
|
14 | ```javascript
|
15 | var R = require("./rlab");
|
16 | var c = console;
|
17 |
|
18 | var x = R.samples(R.range(0,100, 10), {size:10, replace:true});
|
19 | c.log("x=", x);
|
20 |
|
21 | var x = R.samples(R.range(1,6), {size:10, replace:false});
|
22 | c.log("x=%j max=%d min=%d mean=%d", x, R.max(x), R.min(x), R.mean(x));
|
23 |
|
24 | c.log("cov(x,x)=", R.cov(x,x));
|
25 | c.log("cor(x,x)=", R.cor(x,x)); // 相關係數
|
26 | c.log("factorial(10)=", R.factorial(10)); // 階層 n!
|
27 | c.log("lfactorial(10)=", R.lfactorial(10)); // log(n!)
|
28 | c.log("choose(5,2)=", R.choose(5,2)); // 組合 C(n,m)
|
29 | c.log("lchoose(5,2)=", R.lchoose(5,2)); // log C(n,m)
|
30 | c.log("permutation(5,2)=", R.permutation(5,2)); // P(n,m)
|
31 |
|
32 | c.log("runif(10, -5, -1)=", R.runif(10, -5, -1));
|
33 | c.log("rnorm(10, 5, 2)=", R.rnorm(10, 5, 2));
|
34 | ```
|
35 |
|
36 | ## run
|
37 |
|
38 | ```
|
39 | $ node rtest
|
40 | x=[1,3,2,6,3,2,5,4,4,3] max=6 min=1 mean=3.3
|
41 | x= [ 20, 50, 10, 0, 80, 60, 70, 30, 100, 90 ]
|
42 | ```
|
43 |
|
44 |
|