- 安裝R 與Rstudio
- Rstudio 功能簡介
- 上手R 程式撰寫
Wush Wu
國立台灣大學
sudo sh -c 'echo "deb http://cran.csie.ntu.edu.tw/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt-get update && apt-get install -y r-base libcurl4-openssl-dev libxml2-dev espeak
expression
(敘述)expression
expression
>
代表「R 正準備接受下一個expression」Enter
代表一個expression的結束expression
expression
+
代表「R 認為expression沒有結束」ESC
可以中斷expressionexpression
#
之後的程式碼不會被處理,稱為「註解」[1] 2
0
或1
是一個位元(bit)0
或1
是一個位元組(Bytes)0
: 女性、1
:男性或是看課堂老師的說明
y = x + 1
x 代入 1 則 y 為 2
x 代入 2 則 y 為 3
"
所夾住的文字,在程式碼中會視為字串(character)[1] 2
[1] "1 + 1"
[1] 307.0831
x
萬人的身份證字號與性別需要多大的記憶體(MB)?[1] 36.04889
[1] 53.40576
描述從名字到值的關係
r
x = 270
x
是名字、值則是270
x = 270
這類型的程式碼被稱為assignment
(賦值)
assignment
是不是一種expression
?在R 裡面,以下都是assignment
# 雲林縣的人口有69萬人、苗栗縣有56萬人、新竹縣有55萬人、嘉義縣有52萬人,
# 請問儲存以上縣市所有的身份證字號(用10個文字,10 Bytes)、性別(用整數,4 Bytes)與電話號碼(用整數4 Bytes)
# 需要多少記憶體(MB)? 請用x 的方式寫
x <- <數字>
x * 10000 * (<每儲存一個人的資訊所需要的記憶體大小>) / 1024 / 1024
<數字>
與<每儲存一個人的資訊所需要的記憶體大小>
替換成你的expression
x <- <數字>
可以算出不同的答案[1] 11.84464
[1] 9.613037
[1] 9.441376
x
, 輸出是x * 10000 * (10 + 4 + 4) / 1024 / 1024
f <- function(x) x * 10000 * (10 + 4 + 4) / 1024 / 1024
[1] 11.84464
[1] 9.613037
[1] 9.441376
[1] 8.926392
[1] 2.5
[1] 2.5
mean
: 函數的名字(
、)
: 括號。名字後面接括號,代表這個名字的變數是一種函數a
: arguments
(參數)mean(x)
mean
: 算平均數sd
: 算樣本標準差mean(x)
: 計算x 的平均數mean(y)
: 計算y 的平均數mean(x, na.rm = TRUE)
: 計算x 的平均數,不包含遺失值XML
、xml2
、jsonlite
httr
supc
dplyr
ggplot2
Lahman
examples
demo
vignettes
install.packages("ctv")
Error in library(ctv): there is no package called 'ctv'
Error in loadNamespace(name): there is no package called 'ctv'
Error in x[[5]]: subscript out of bounds
function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages
負責安裝套件
電腦需要知道動作的細節才能運作:
function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages
的參數有: pkg
、lib
、repos
...
pkg
代表「要安裝的套件的名稱」repos
代表「提供套件的網站」function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages("ctv")
pkg
: "ctv"
function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages("ctv", "http://cran.csie.ntu.edu.tw")
pkg
: "ctv"
lib
: "http://cran.csie.ntu.edu.tw"
function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages("ctv", repos = "http://cran.csie.ntu.edu.tw")
pkg
: "ctv"
repos
: "http://cran.csie.ntu.edu.tw"
function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages("ctv", repo = "http://cran.csie.ntu.edu.tw")
pkg
: "ctv"
repos
: "http://cran.csie.ntu.edu.tw"
function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages("ctv", "http://cran.csie.ntu.edu.tw", lib = "/home/wush/Project/2017-DS-Programming/.lib")
pkg
: "ctv"
lib
: "/home/wush/Project/2017-DS-Programming/.lib"
repos
: "http://cran.csie.ntu.edu.tw"
function (pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos,
type), method, available = NULL, destdir = NULL, dependencies = NA,
type = getOption("pkgType"), configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"), clean = FALSE,
Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE,
...)
NULL
install.packages("ctv")
repos
: getOption("repos")
destdir
: NULL
function (x, split, fixed = FALSE, perl = FALSE, useBytes = FALSE)
NULL
[[1]]
[1] "ab" "ef"
x
、split
、fixed
、perl
與useBytes
的值各為何?