如何在 R 軟體中安裝與引入套件

統計軟體 R

簡介

安裝

操作方式

變數與運算

有序數列

向量

矩陣

多維陣列

複數

因子

串列

資料框

時間數列

流程控制

輸出入

呼叫

函數

2D 繪圖

3D 繪圖

互動介面

套件列表

其他語言呼叫

R 的應用

集合

邏輯推論

模糊邏輯

機率邏輯

檢定

搜尋

優化算法

線性代數

決策樹

人工智慧

分群分類

SVM 向量機

神經網路

遺傳演算法

資料採礦

訊號處理

影像處理

語音處理

自然語言

機器學習

機器人

生物統計

數位訊號處理

方程式求解

數值分析

微積分

微分方程

線性規劃

圖形理論

統計推論

字串處理

正規表示式

視窗程式

網頁程式

文件格式

貝氏網路

訊息

機率統計書

相關網站

參考文獻

最新修改

簡體版

English

套件引用

我們可以使用 library(package_name) 引用套件,將函式庫引入,才能開始使用該套件中的函數,以下範例引用了 Matrix 套件,所以我們就可以使用其中的 LU 分解函數 lu()。

> library(Matrix)
Loading required package: lattice

Attaching package: 'Matrix'

The following object(s) are masked from 'package:base':

    det

> a = Matrix((1:16)^2, nrow=4, ncol=4)
> a
4 x 4 Matrix of class "dgeMatrix"
     [,1] [,2] [,3] [,4]
[1,]    1   25   81  169
[2,]    4   36  100  196
[3,]    9   49  121  225
[4,]   16   64  144  256
> lu = lu(a)

套件安裝 (以 TSA 為例)

> install.packages("TSA")
Installing package(s) into ‘C:/Users/Guest/Documents/R/win-library/2.13’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
also installing the dependencies ‘akima’, 
‘quadprog’, ‘zoo’, ‘leaps’, ‘locfit’, ‘tseries’

試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/akima_0.5-4.zip'
Content type 'application/zip' length 324270 bytes (316 Kb)
開啟了 URL
downloaded 316 Kb

試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/quadprog_1.5-4.zip'
Content type 'application/zip' length 45600 bytes (44 Kb)
開啟了 URL
downloaded 44 Kb

試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/zoo_1.7-4.zip'
Content type 'application/zip' length 1376578 bytes (1.3 Mb)
開啟了 URL
downloaded 1.3 Mb

試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/leaps_2.9.zip'
Content type 'application/zip' length 232967 bytes (227 Kb)
開啟了 URL
downloaded 227 Kb

試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/locfit_1.5-6.zip'
Content type 'application/zip' length 537623 bytes (525 Kb)
開啟了 URL
downloaded 525 Kb

試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/tseries_0.10-26.zip'
Content type 'application/zip' length 303090 bytes (295 Kb)
開啟了 URL
downloaded 295 Kb

試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/TSA_0.98.zip'
Content type 'application/zip' length 372469 bytes (363 Kb)
開啟了 URL
downloaded 363 Kb

package 'akima' successfully unpacked and MD5 sums checked
package 'quadprog' successfully unpacked and MD5 sums checked
package 'zoo' successfully unpacked and MD5 sums checked
package 'leaps' successfully unpacked and MD5 sums checked
package 'locfit' successfully unpacked and MD5 sums checked
package 'tseries' successfully unpacked and MD5 sums checked
package 'TSA' successfully unpacked and MD5 sums checked

The downloaded packages are in
        C:\Users\Guest\AppData\Local\Temp\RtmparvoFV\downloaded_packages
> 
> library(TSA)
Loading required package: leaps
Loading required package: locfit
Loading required package: akima
Loading required package: lattice
locfit 1.5-6     2010-01-20 
Loading required package: mgcv
This is mgcv 1.7-6. For overview type 'help("mgcv-package")'.
Loading required package: tseries
Loading required package: quadprog
Loading required package: zoo

Attaching package: 'zoo'

The following object(s) are masked from 'package:base':

    as.Date

    ‘tseries’ version: 0.10-26    ‘tseries’ is a package for 
         time series analysis  and    computational finance.    
    See ‘library(help="tseries")’ for details.

Attaching package: 'TSA'

The following object(s) are masked from 'package:stats':

    acf, arima

The following object(s) are masked from 'package:utils':

    tar

> skewness(x)
[1] 0.4985052
> kurtosis(x)
[1] -1.10491

套件安裝 epicalc

> install.packages(epicalc)
錯誤在install.packages(epicalc) : 找不到目的物件 'epicalc'
> install.packages("epicalc")
Installing package(s) into ‘C:/Users/Guest/Documents/R/win-library/2.13’
(as ‘lib’ is unspecified)
試開URL 'http://cran.cs.pu.edu.tw/bin/windows/contrib/2.13/epicalc_2.13.1.3.zip'
Content type 'application/zip' length 435047 bytes (424 Kb)
開啟了 URL
downloaded 424 Kb

package 'epicalc' successfully unpacked and MD5 sums checked

The downloaded packages are in
        C:\Users\Guest\AppData\Local\Temp\RtmparvoFV\downloaded_packages

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License