這是我在念博士班(2009)時整理的一些中文介紹, 懶得再重新修改了...
給有興趣的人參考囉...
基本上, 我現在最常用的就只有browser(), 我是覺得學了這個就夠用了....^^
有空再來重新檢視過內容~~
PDF: debuggingR
2013年4月2日 星期二
2013年1月31日 星期四
利用R的Rmpi來做平行化運算..
筆電Toshiba Satellite C640, Linux Mint 13
速度, 本來需要578.18 secs, 加上平行化後只需209.99 secs.
R 程式碼
速度, 本來需要578.18 secs, 加上平行化後只需209.99 secs.
R 程式碼
rm(list=ls())
library(snow)
myfun <- function(ii) {
set.seed(ii*100)
ret = mean(rnorm(10000))
ret
}
cluster = makeCluster(4,type="MPI")
### Normal
tt0 = Sys.time()
aa = sapply(1:100000,myfun)
tt1 = Sys.time()
bb = parSapply(cluster,1:100000,myfun)
tt2 = Sys.time()
stopCluster(cluster)
cat(sprintf(" - %.4f, %.4f\n",difftime(tt1,tt0,units="secs"),difftime(tt2,tt1,units="secs")))
在unix上安裝自己的R
工作站的R是舊版的2.13.2
- 到CRAN下載R的source code
$ wget http://cran.csie.ntu.edu.tw/src/base/R-2/R-2.15.2.tar.gz - 解壓縮到暫存目錄後, 先用./configure來客制化, 比如我把R裝載~/software/R-2.15.2下面
$ ./configure --with-x --prefix=/home/u00yhh00/software/R-2.15.2 --enable-R-shlib - 接下來就是一連串的等待時間了, 利用make & make install來安裝
$ make & make install - 修改自己目錄下的.bashrc這個檔案, 設定路徑
export PATH=/home/u00yhh00/software/R-2.15.2/bin:PATH - 重新登入, 或者是下source指令
$ source .bashrc - 已經成功更新到2.15.2囉...
2013年1月20日 星期日
MATLAB vs. R
MATLAB與R都是矩陣運算的程式語言, 各有優缺點...
這是這兩種語言的一些function說明與比較, 在R官方網頁可以下載~
http://cran.r-project.org/doc/contrib/Hiebeler-matlabR.pdf
這是這兩種語言的一些function說明與比較, 在R官方網頁可以下載~
http://cran.r-project.org/doc/contrib/Hiebeler-matlabR.pdf
2013年1月9日 星期三
[R] 交互對談指令
其實是一個小技巧, 因為某人是程式白癡, 我又不可能幫他跑所有可能組合...
所以只能把程式丟給他跑, 為了要讓介面人性化一點, 決定要用"交談式"的參數輸入~~
舉例來說, 下面的小函數就可以由使用者決定一個方陣的大小...
只要把這個code給copy/paste到R去, 就可以用demo()來跑程式了...
demo <- font="font" function="function">->
cat(" - Please input the size of matrix: ")
n = readLines(n=1)
n = as.numeric(n)
mat = matrix(1,ncol=n,nrow=n)
print(mat)
}
> demo()
- Please input the size of matrix: 3
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
>
所以只能把程式丟給他跑, 為了要讓介面人性化一點, 決定要用"交談式"的參數輸入~~
舉例來說, 下面的小函數就可以由使用者決定一個方陣的大小...
只要把這個code給copy/paste到R去, 就可以用demo()來跑程式了...
demo <- font="font" function="function">->
cat(" - Please input the size of matrix: ")
n = readLines(n=1)
n = as.numeric(n)
mat = matrix(1,ncol=n,nrow=n)
print(mat)
}
> demo()
- Please input the size of matrix: 3
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
>
2011年4月3日 星期日
[R] 畫圖時把兩個座標軸的scale調成一樣
網路上看到的小技巧, 原文在
簡單來說, 就是在plot()中加入一個參數asp=1...
檢附上面連結的example如下, 有空再來研究...
---
x <- sample(10:200,40)
y <- sample(20:100,40)
windows(width = max(x),height = max(y))
plot(x,y)
# try:
plot(x, y, asp = 1)
# or, better:
library(MASS)
eqscplot(x,y)
#or
library(lattice)
xyplot(y ~ x, aspect = "iso")
y <- sample(20:100,40)
windows(width = max(x),height = max(y))
plot(x,y)
# try:
plot(x, y, asp = 1)
# or, better:
library(MASS)
eqscplot(x,y)
#or
library(lattice)
xyplot(y ~ x, aspect = "iso")
訂閱:
文章 (Atom)

