0
即時轉換R腳本爲JavaScript,以便我可以動態更改HightCharts.js圖。然而,我不知道如何編寫JavaScript函數來模擬R中的rnorm()函數。任何有關解決這個問題的建議都是非常值得讚賞的。將R轉換爲javascript用於highcharts.js
這是R代碼..
## create random normal variables with correct mean and standard deviations
RHT <- round(rnorm(50, mean= HTot, sd= HtX))
RAT <- round(rnorm(50, mean= ATot , sd= AtX))
## combine data
ranScor <- cbind(RHT,RAT)
ranScor <- data.frame(ranScor)
### plotting simple line graph
plot(RHT,type="b", col= "blue", lwd=1, ylim=c(min(ranScor),max(ranScor)),xlab="Game Simulations",ylab="Team Score", main="Random Score Generator", sub="Indianapolis Colts @ Denver Broncos")
lines(RAT, type="b", col="red",lwd=1)
legend("topleft",legend=c("HomeTeam","AwayTeam"),lty=1,col=c("blue","red"),lwd=2,cex=.7)
https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform –
你可以仔細閱讀標準正常R源之中,有是一些算法,https://github.com/wch/r-source/blob/trunk/src/nmath/snorm.c – jenesaisquoi
[highchartR](https://github.com/jcizel/highchartR) – hrbrmstr