what is R? - https://zh.wikipedia.org/wiki/R%E8%AF%AD%E8%A8%80

R vs Python? - https://www.datacamp.com/community/tutorials/r-or-python-for-data-analysis - https://www.kdnuggets.com/2019/05/poll-top-data-science-machine-learning-platforms.html

Kaggle - https://www.kaggle.com/

UCI dataset - https://archive.ics.uci.edu/ml/datasets.html

電子檔講義 - https://www.dropbox.com/s/bhqmpndutktw401/201806%20-%20R%E8%AA%9E%E8%A8%80.pdf?dl=0

R intro

RDemo

#使用範例資料
data(anscombe)
#使用資料中x1,y1變數畫出點散布圖
plot(y1 ~ x1, data = anscombe)
#建立回歸模型並assign到lmfit變數中
lmfit <- lm(y1~x1, data=anscombe) 
#在點散佈圖上加上迴歸線
abline(lmfit, col="red")

Basic type

  • numeric: 1,2,1.2
  • integer: 1L,2L,3L
  • character: “string”
  • logical: TRUE,FALSE,T,F
  • complex: 1+4i
  • date: “2018-05-01”
  • posixct, posixlt: “2018-05-01 08:00:00 CST”

Basic Objects

(由相同資料型態組成)
atomic:
  • vector
  • matrix
  • factor
(可以有混合的資料型態)
recursive:
  • dataframe
  • list

R basic command

#文件查詢
help(package="base")
?base::sum
?sum
help.search("sum")
??sum

#範例演釋
demo()
#使用內建資料集
data()
#看現有變數
ls()
## [1] "anscombe" "lmfit"
#移除變數
rm()

x = c(1,2,3)
#查看資料型態
class(x)
## [1] "numeric"
#查看資料結構
str(x)
##  num [1:3] 1 2 3

Basic computing

3+8
## [1] 11
3-8
## [1] -5
3*8
## [1] 24
3/8
## [1] 0.375
11%%2
## [1] 1
3<4
## [1] TRUE
2==5
## [1] FALSE
T == TRUE
## [1] TRUE

Assignment

a = 3
a <- 3 # ( alt + - )
assign("a",3)

a / 2
## [1] 1.5
a = a / 2
a
## [1] 1.5

Vector

  • R語言最基本的物件
character(5)  ## character vector of length 5
## [1] "" "" "" "" ""
numeric(5)
## [1] 0 0 0 0 0
logical(5)
## [1] FALSE FALSE FALSE FALSE FALSE
x = c(1,2,3,7)
y= c(2,3,5,1)
x+y
## [1] 3 5 8 8
x*y
## [1]  2  6 15  7
x-y
## [1] -1 -1 -2  6
x/y
## [1] 0.5000000 0.6666667 0.6000000 7.0000000
x = c(1,2,3,7)
x + 10
## [1] 11 12 13 17
x + c(10)
## [1] 11 12 13 17
x + c(1,2)
## [1] 2 4 4 9
x + c(1,2,1,2)
## [1] 2 4 4 9
x == c(1,99,3,4)
## [1]  TRUE FALSE  TRUE FALSE
c(1,2,3)
## [1] 1 2 3
c(2,T,3+0i,"one")
## [1] "2"    "TRUE" "3+0i" "one"
c(2,T,3+0i)
## [1] 2+0i 1+0i 3+0i
c(c(1,2,3,4),c(5))
## [1] 1 2 3 4 5
x = c(1,2,3,4,NA)
sum(x)
## [1] NA
sum(x, na.rm=T)
## [1] 10
x = c(1,2,3,4,NA)
is.na(x)
## [1] FALSE FALSE FALSE FALSE  TRUE
sum(x[!is.na(x)])
## [1] 10
height_vec = c(180,169,173)
height_vec
## [1] 180 169 173
names(height_vec) = c("Brian", "Toby", "Sherry")
height_vec
##  Brian   Toby Sherry 
##    180    169    173
name_vec = c("Brian", "Toby", "Sherry")
names(height_vec) = name_vec
height_vec > 175
##  Brian   Toby Sherry 
##   TRUE  FALSE  FALSE
height_vec / 100
##  Brian   Toby Sherry 
##   1.80   1.69   1.73
height_vec > 175 | height_vec < 170
##  Brian   Toby Sherry 
##   TRUE   TRUE  FALSE
height_vec < 175 & height_vec > 170
##  Brian   Toby Sherry 
##  FALSE  FALSE   TRUE
#R 的index從1開始
height_vec[c(1)] #index
## Brian 
##   180
height_vec['Brian'] #element name
## Brian 
##   180
height_vec[height_vec > 175] #condition (boolean vector)
## Brian 
##   180

p38 example

h = c(180,169,173)
w = c(73,87,43)
bmi = w / ((h/100)^2)
names(bmi) = c("Brian", "Toby", "Sherry")
bmi < 18.5 | bmi >= 24
##  Brian   Toby Sherry 
##  FALSE   TRUE   TRUE
bmi[bmi < 18.5 | bmi >= 24]
##     Toby   Sherry 
## 30.46112 14.36734

seq() & rep() & paste()

1:20
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
seq(1,20)
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
20:1
##  [1] 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1
?seq
seq(from=1,to=20,by=2)
##  [1]  1  3  5  7  9 11 13 15 17 19
seq(from=1,to=20,length=2)
## [1]  1 20
rep(1,5)
## [1] 1 1 1 1 1
?rep
rep(x=c(1,2), times=5)
##  [1] 1 2 1 2 1 2 1 2 1 2
rep(x=c(1,2), times=c(1,2))
## [1] 1 2 2
rep(x=c(1,2), each=5)
##  [1] 1 1 1 1 1 2 2 2 2 2
rep(x=c(1,2), length=5)
## [1] 1 2 1 2 1
rep_len(x=c(1,2),length.out = 5)
## [1] 1 2 1 2 1
paste("the","big","bang","theory")
## [1] "the big bang theory"
paste("big","bang",sep="-")
## [1] "big-bang"
length(paste("the","big","bang","theory"))
## [1] 1
paste("big","bang",sep="")
## [1] "bigbang"
paste("big","bang",sep=";")
## [1] "big;bang"
paste(c("big","bang"),1:2)
## [1] "big 1"  "bang 2"
paste(c("big","bang"),1:2,collapse = "+" )
## [1] "big 1+bang 2"
length(paste(c("big","bang"),1:4,collapse = "+" ))
## [1] 1
data(iris)
pct = table(iris[,"Species"]) / length(iris[,"Species"])
paste(round(pct * 100,2), "%")
## [1] "33.33 %" "33.33 %" "33.33 %"

Matrix

matrix(1:9, byrow=TRUE, nrow=3)
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9
matrix(1:9, nrow=3)
##      [,1] [,2] [,3]
## [1,]    1    4    7
## [2,]    2    5    8
## [3,]    3    6    9
kevin = c(85,73)
marry = c(72,64)
jerry = c(59,66)
mat = matrix(c(kevin, marry, jerry), nrow=3, byrow= TRUE)
colnames(mat) = c('first', 'second')
rownames(mat) = c('kevin', 'marry', 'jerry')
mat
##       first second
## kevin    85     73
## marry    72     64
## jerry    59     66
#取得矩陣維度
dim(mat)
## [1] 3 2
#取得矩陣列數
nrow(mat)
## [1] 3
#取得矩陣欄數
ncol(mat)
## [1] 2
#矩陣轉置(transpose)
t(mat)
##        kevin marry jerry
## first     85    72    59
## second    73    64    66
#取第一列
mat[1,]
##  first second 
##     85     73
#取第一行
mat[,1]
## kevin marry jerry 
##    85    72    59
#取第一、二列
mat[1:2,]
##       first second
## kevin    85     73
## marry    72     64
#取kevin和jerry成績
mat[c('kevin','jerry'),]
##       first second
## kevin    85     73
## jerry    59     66
#取kevin和jerry成績的第一次考試成績
mat[c('kevin','jerry'),'first']
## kevin jerry 
##    85    59
#取得第一次考試成績不及格的人
mat[mat[,1] < 60,'first']
## [1] 59
rowSums(mat)
## kevin marry jerry 
##   158   136   125
colSums(mat)
##  first second 
##    216    203
rowMeans(mat)
## kevin marry jerry 
##  79.0  68.0  62.5
colMeans(mat)
##    first   second 
## 72.00000 67.66667
#新增列與行
mat2 = rbind(mat, c(78,63))
rownames(mat2)[nrow(mat2)] = 'sam'
mat2
##       first second
## kevin    85     73
## marry    72     64
## jerry    59     66
## sam      78     63
mat3 = cbind(mat2,c(82,77,70,64))
colnames(mat3)[ncol(mat3)] = 'third'
mat3
##       first second third
## kevin    85     73    82
## marry    72     64    77
## jerry    59     66    70
## sam      78     63    64
rowMeans(mat3)
##    kevin    marry    jerry      sam 
## 80.00000 71.00000 65.00000 68.33333
colMeans(mat3)
##  first second  third 
##  73.50  66.50  73.25
# arithmetic
m1 = matrix(1:4, byrow=TRUE, nrow=2)
m2 = matrix(5:8, byrow=TRUE, nrow=2)

m1 + m2
##      [,1] [,2]
## [1,]    6    8
## [2,]   10   12
m1 - m2
##      [,1] [,2]
## [1,]   -4   -4
## [2,]   -4   -4
m1 * m2
##      [,1] [,2]
## [1,]    5   12
## [2,]   21   32
m1 / m2
##           [,1]      [,2]
## [1,] 0.2000000 0.3333333
## [2,] 0.4285714 0.5000000
m1 %*% m2
##      [,1] [,2]
## [1,]   19   22
## [2,]   43   50

p54 example

kevin = c(85,73)
marry = c(72,64)
jerry = c(59,66)
mat = matrix(c(kevin, marry, jerry), nrow=3, byrow= TRUE)
colnames(mat) = c('first', 'second')
rownames(mat) = c('kevin', 'marry', 'jerry')

final = mat %*% c(0.4,0.6)
final
##       [,1]
## kevin 77.8
## marry 67.2
## jerry 63.2
cbind(mat,final)
##       first second     
## kevin    85     73 77.8
## marry    72     64 67.2
## jerry    59     66 63.2
mat2 = cbind(mat,final)
mat2
##       first second     
## kevin    85     73 77.8
## marry    72     64 67.2
## jerry    59     66 63.2
colnames(mat2)[ncol(mat2)] = 'final'
mat2
##       first second final
## kevin    85     73  77.8
## marry    72     64  67.2
## jerry    59     66  63.2
#type priority
c("string",1+2i,5.5,TRUE)
## [1] "string" "1+2i"   "5.5"    "TRUE"
c(1+2i,5.5,TRUE)
## [1] 1.0+2i 5.5+0i 1.0+0i
c(5.5,TRUE)
## [1] 5.5 1.0
#as.
as.data.frame(mat)
##       first second
## kevin    85     73
## marry    72     64
## jerry    59     66
as.character(1034)
## [1] "1034"
#is.
is.matrix(mat)
## [1] TRUE
is.data.frame(mat)
## [1] FALSE
is.numeric(mat)
## [1] TRUE
is.character(mat)
## [1] FALSE
#is.na
sum(c(1,2,3,NA))
## [1] NA
sum(c(1,2,3,NA),na.rm=T)
## [1] 6
is.na(c(1,2,3,NA))
## [1] FALSE FALSE FALSE  TRUE
c(1,2,3,NA)[is.na(c(1,2,3,NA))]
## [1] NA
is.na(c(1,2,3,NA))
## [1] FALSE FALSE FALSE  TRUE
!is.na(c(1,2,3,NA))
## [1]  TRUE  TRUE  TRUE FALSE
c(1,2,3,NA)[!is.na(c(1,2,3,NA))]
## [1] 1 2 3
sum(c(1,2,3,NA)[!is.na(c(1,2,3,NA))])
## [1] 6

Factor

# syntax
weather= c("sunny","rainy", "cloudy", "rainy", "cloudy")
weather_category = factor(weather)
weather_category
## [1] sunny  rainy  cloudy rainy  cloudy
## Levels: cloudy rainy sunny
class(weather)
## [1] "character"
class(weather_category)
## [1] "factor"
levels(weather_category)
## [1] "cloudy" "rainy"  "sunny"
weather_category[6] = 'cloudy'
weather_category[7] = 'typhoon'
## Warning in `[<-.factor`(`*tmp*`, 7, value = "typhoon"): invalid factor
## level, NA generated
levels(weather_category)[4] = 'typhoon'
levels(weather_category)
## [1] "cloudy"  "rainy"   "sunny"   "typhoon"
weather_category[7] = 'typhoon'
weather_category
## [1] sunny   rainy   cloudy  rainy   cloudy  cloudy  typhoon
## Levels: cloudy rainy sunny typhoon
# order
temperature = c("Low", "High", "High", "Medium", "Low", "Medium")
temperature_category = factor(temperature, order = TRUE, levels = c("Low", "Medium", "High"))
temperature_category
## [1] Low    High   High   Medium Low    Medium
## Levels: Low < Medium < High
temperature_category[3] > temperature_category[1]
## [1] TRUE
temperature_category[4] > temperature_category[3]
## [1] FALSE
# change levels name
weather= c("s","r", "c", "r", "c")
weather_factor = factor(weather)
levels(weather_factor) = c("cloudy","rainy","sunny")
weather_factor
## [1] sunny  rainy  cloudy rainy  cloudy
## Levels: cloudy rainy sunny

Dataframe

name <- c("Joe", "Bob", "Vicky")
age <- c(28, 26, 34)
gender <- c("Male","Male","Female")
df <- data.frame(name, age, gender)
class(df)
## [1] "data.frame"
str(df)
## 'data.frame':    3 obs. of  3 variables:
##  $ name  : Factor w/ 3 levels "Bob","Joe","Vicky": 2 1 3
##  $ age   : num  28 26 34
##  $ gender: Factor w/ 2 levels "Female","Male": 2 2 1
data(iris)
head(iris)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
tail(iris)
##     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
## 145          6.7         3.3          5.7         2.5 virginica
## 146          6.7         3.0          5.2         2.3 virginica
## 147          6.3         2.5          5.0         1.9 virginica
## 148          6.5         3.0          5.2         2.0 virginica
## 149          6.2         3.4          5.4         2.3 virginica
## 150          5.9         3.0          5.1         1.8 virginica
tail(iris, 10)
##     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
## 141          6.7         3.1          5.6         2.4 virginica
## 142          6.9         3.1          5.1         2.3 virginica
## 143          5.8         2.7          5.1         1.9 virginica
## 144          6.8         3.2          5.9         2.3 virginica
## 145          6.7         3.3          5.7         2.5 virginica
## 146          6.7         3.0          5.2         2.3 virginica
## 147          6.3         2.5          5.0         1.9 virginica
## 148          6.5         3.0          5.2         2.0 virginica
## 149          6.2         3.4          5.4         2.3 virginica
## 150          5.9         3.0          5.1         1.8 virginica
str(iris)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
#取前三列資料
iris[1:3,]
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
#取前三列第一行的資料
iris[1:3,1]
## [1] 5.1 4.9 4.7
#取前三列Sepal.Length欄位的資料
iris[1:3,"Sepal.Length"]
## [1] 5.1 4.9 4.7
head(iris[,1:2])
##   Sepal.Length Sepal.Width
## 1          5.1         3.5
## 2          4.9         3.0
## 3          4.7         3.2
## 4          4.6         3.1
## 5          5.0         3.6
## 6          5.4         3.9
iris$"Sepal.Length"[1:3]
## [1] 5.1 4.9 4.7
#取前五筆包含length 及 width 的資料
Five.Sepal.iris = iris[1:5, c("Sepal.Length","Sepal.Width")]
#可以用條件做篩選
setosa.data = iris[iris$Species=="setosa",1:5]
str(setosa.data)
## 'data.frame':    50 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
#使用which 做資料篩選
which(iris$Species=="setosa")
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## [24] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
## [47] 47 48 49 50
#用order做資料排序
iris[order(iris$Sepal.Length, decreasing = TRUE),]
##     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 132          7.9         3.8          6.4         2.0  virginica
## 118          7.7         3.8          6.7         2.2  virginica
## 119          7.7         2.6          6.9         2.3  virginica
## 123          7.7         2.8          6.7         2.0  virginica
## 136          7.7         3.0          6.1         2.3  virginica
## 106          7.6         3.0          6.6         2.1  virginica
## 131          7.4         2.8          6.1         1.9  virginica
## 108          7.3         2.9          6.3         1.8  virginica
## 110          7.2         3.6          6.1         2.5  virginica
## 126          7.2         3.2          6.0         1.8  virginica
## 130          7.2         3.0          5.8         1.6  virginica
## 103          7.1         3.0          5.9         2.1  virginica
## 51           7.0         3.2          4.7         1.4 versicolor
## 53           6.9         3.1          4.9         1.5 versicolor
## 121          6.9         3.2          5.7         2.3  virginica
## 140          6.9         3.1          5.4         2.1  virginica
## 142          6.9         3.1          5.1         2.3  virginica
## 77           6.8         2.8          4.8         1.4 versicolor
## 113          6.8         3.0          5.5         2.1  virginica
## 144          6.8         3.2          5.9         2.3  virginica
## 66           6.7         3.1          4.4         1.4 versicolor
## 78           6.7         3.0          5.0         1.7 versicolor
## 87           6.7         3.1          4.7         1.5 versicolor
## 109          6.7         2.5          5.8         1.8  virginica
## 125          6.7         3.3          5.7         2.1  virginica
## 141          6.7         3.1          5.6         2.4  virginica
## 145          6.7         3.3          5.7         2.5  virginica
## 146          6.7         3.0          5.2         2.3  virginica
## 59           6.6         2.9          4.6         1.3 versicolor
## 76           6.6         3.0          4.4         1.4 versicolor
## 55           6.5         2.8          4.6         1.5 versicolor
## 105          6.5         3.0          5.8         2.2  virginica
## 111          6.5         3.2          5.1         2.0  virginica
## 117          6.5         3.0          5.5         1.8  virginica
## 148          6.5         3.0          5.2         2.0  virginica
## 52           6.4         3.2          4.5         1.5 versicolor
## 75           6.4         2.9          4.3         1.3 versicolor
## 112          6.4         2.7          5.3         1.9  virginica
## 116          6.4         3.2          5.3         2.3  virginica
## 129          6.4         2.8          5.6         2.1  virginica
## 133          6.4         2.8          5.6         2.2  virginica
## 138          6.4         3.1          5.5         1.8  virginica
## 57           6.3         3.3          4.7         1.6 versicolor
## 73           6.3         2.5          4.9         1.5 versicolor
## 88           6.3         2.3          4.4         1.3 versicolor
## 101          6.3         3.3          6.0         2.5  virginica
## 104          6.3         2.9          5.6         1.8  virginica
## 124          6.3         2.7          4.9         1.8  virginica
## 134          6.3         2.8          5.1         1.5  virginica
## 137          6.3         3.4          5.6         2.4  virginica
## 147          6.3         2.5          5.0         1.9  virginica
## 69           6.2         2.2          4.5         1.5 versicolor
## 98           6.2         2.9          4.3         1.3 versicolor
## 127          6.2         2.8          4.8         1.8  virginica
## 149          6.2         3.4          5.4         2.3  virginica
## 64           6.1         2.9          4.7         1.4 versicolor
## 72           6.1         2.8          4.0         1.3 versicolor
## 74           6.1         2.8          4.7         1.2 versicolor
## 92           6.1         3.0          4.6         1.4 versicolor
## 128          6.1         3.0          4.9         1.8  virginica
## 135          6.1         2.6          5.6         1.4  virginica
## 63           6.0         2.2          4.0         1.0 versicolor
## 79           6.0         2.9          4.5         1.5 versicolor
## 84           6.0         2.7          5.1         1.6 versicolor
## 86           6.0         3.4          4.5         1.6 versicolor
## 120          6.0         2.2          5.0         1.5  virginica
## 139          6.0         3.0          4.8         1.8  virginica
## 62           5.9         3.0          4.2         1.5 versicolor
## 71           5.9         3.2          4.8         1.8 versicolor
## 150          5.9         3.0          5.1         1.8  virginica
## 15           5.8         4.0          1.2         0.2     setosa
## 68           5.8         2.7          4.1         1.0 versicolor
## 83           5.8         2.7          3.9         1.2 versicolor
## 93           5.8         2.6          4.0         1.2 versicolor
## 102          5.8         2.7          5.1         1.9  virginica
## 115          5.8         2.8          5.1         2.4  virginica
## 143          5.8         2.7          5.1         1.9  virginica
## 16           5.7         4.4          1.5         0.4     setosa
## 19           5.7         3.8          1.7         0.3     setosa
## 56           5.7         2.8          4.5         1.3 versicolor
## 80           5.7         2.6          3.5         1.0 versicolor
## 96           5.7         3.0          4.2         1.2 versicolor
## 97           5.7         2.9          4.2         1.3 versicolor
## 100          5.7         2.8          4.1         1.3 versicolor
## 114          5.7         2.5          5.0         2.0  virginica
## 65           5.6         2.9          3.6         1.3 versicolor
## 67           5.6         3.0          4.5         1.5 versicolor
## 70           5.6         2.5          3.9         1.1 versicolor
## 89           5.6         3.0          4.1         1.3 versicolor
## 95           5.6         2.7          4.2         1.3 versicolor
## 122          5.6         2.8          4.9         2.0  virginica
## 34           5.5         4.2          1.4         0.2     setosa
## 37           5.5         3.5          1.3         0.2     setosa
## 54           5.5         2.3          4.0         1.3 versicolor
## 81           5.5         2.4          3.8         1.1 versicolor
## 82           5.5         2.4          3.7         1.0 versicolor
## 90           5.5         2.5          4.0         1.3 versicolor
## 91           5.5         2.6          4.4         1.2 versicolor
## 6            5.4         3.9          1.7         0.4     setosa
## 11           5.4         3.7          1.5         0.2     setosa
## 17           5.4         3.9          1.3         0.4     setosa
## 21           5.4         3.4          1.7         0.2     setosa
## 32           5.4         3.4          1.5         0.4     setosa
## 85           5.4         3.0          4.5         1.5 versicolor
## 49           5.3         3.7          1.5         0.2     setosa
## 28           5.2         3.5          1.5         0.2     setosa
## 29           5.2         3.4          1.4         0.2     setosa
## 33           5.2         4.1          1.5         0.1     setosa
## 60           5.2         2.7          3.9         1.4 versicolor
## 1            5.1         3.5          1.4         0.2     setosa
## 18           5.1         3.5          1.4         0.3     setosa
## 20           5.1         3.8          1.5         0.3     setosa
## 22           5.1         3.7          1.5         0.4     setosa
## 24           5.1         3.3          1.7         0.5     setosa
## 40           5.1         3.4          1.5         0.2     setosa
## 45           5.1         3.8          1.9         0.4     setosa
## 47           5.1         3.8          1.6         0.2     setosa
## 99           5.1         2.5          3.0         1.1 versicolor
## 5            5.0         3.6          1.4         0.2     setosa
## 8            5.0         3.4          1.5         0.2     setosa
## 26           5.0         3.0          1.6         0.2     setosa
## 27           5.0         3.4          1.6         0.4     setosa
## 36           5.0         3.2          1.2         0.2     setosa
## 41           5.0         3.5          1.3         0.3     setosa
## 44           5.0         3.5          1.6         0.6     setosa
## 50           5.0         3.3          1.4         0.2     setosa
## 61           5.0         2.0          3.5         1.0 versicolor
## 94           5.0         2.3          3.3         1.0 versicolor
## 2            4.9         3.0          1.4         0.2     setosa
## 10           4.9         3.1          1.5         0.1     setosa
## 35           4.9         3.1          1.5         0.2     setosa
## 38           4.9         3.6          1.4         0.1     setosa
## 58           4.9         2.4          3.3         1.0 versicolor
## 107          4.9         2.5          4.5         1.7  virginica
## 12           4.8         3.4          1.6         0.2     setosa
## 13           4.8         3.0          1.4         0.1     setosa
## 25           4.8         3.4          1.9         0.2     setosa
## 31           4.8         3.1          1.6         0.2     setosa
## 46           4.8         3.0          1.4         0.3     setosa
## 3            4.7         3.2          1.3         0.2     setosa
## 30           4.7         3.2          1.6         0.2     setosa
## 4            4.6         3.1          1.5         0.2     setosa
## 7            4.6         3.4          1.4         0.3     setosa
## 23           4.6         3.6          1.0         0.2     setosa
## 48           4.6         3.2          1.4         0.2     setosa
## 42           4.5         2.3          1.3         0.3     setosa
## 9            4.4         2.9          1.4         0.2     setosa
## 39           4.4         3.0          1.3         0.2     setosa
## 43           4.4         3.2          1.3         0.2     setosa
## 14           4.3         3.0          1.1         0.1     setosa
sort(iris$Sepal.Length, decreasing = TRUE)
##   [1] 7.9 7.7 7.7 7.7 7.7 7.6 7.4 7.3 7.2 7.2 7.2 7.1 7.0 6.9 6.9 6.9 6.9
##  [18] 6.8 6.8 6.8 6.7 6.7 6.7 6.7 6.7 6.7 6.7 6.7 6.6 6.6 6.5 6.5 6.5 6.5
##  [35] 6.5 6.4 6.4 6.4 6.4 6.4 6.4 6.4 6.3 6.3 6.3 6.3 6.3 6.3 6.3 6.3 6.3
##  [52] 6.2 6.2 6.2 6.2 6.1 6.1 6.1 6.1 6.1 6.1 6.0 6.0 6.0 6.0 6.0 6.0 5.9
##  [69] 5.9 5.9 5.8 5.8 5.8 5.8 5.8 5.8 5.8 5.7 5.7 5.7 5.7 5.7 5.7 5.7 5.7
##  [86] 5.6 5.6 5.6 5.6 5.6 5.6 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.4 5.4 5.4 5.4
## [103] 5.4 5.4 5.3 5.2 5.2 5.2 5.2 5.1 5.1 5.1 5.1 5.1 5.1 5.1 5.1 5.1 5.0
## [120] 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 4.9 4.9 4.9 4.9 4.9 4.9 4.8 4.8
## [137] 4.8 4.8 4.8 4.7 4.7 4.6 4.6 4.6 4.6 4.5 4.4 4.4 4.4 4.3

File read and write

# getwd()
setwd('~/lecture/riii')
# setwd("__your_working_directory_path__")
tw2330 = read.csv("data/2330.csv", header=TRUE)
#tw2330 = read.csv('https://github.com/YuHsuanLin/riii/raw/master/data/2330.csv')
test.data = read.table("data/match.txt" ,header = FALSE, sep="|")

p70 example

setwd('~/lecture/riii')
tw2330 = read.csv("data/2330.csv", header=TRUE)
str(tw2330)
## 'data.frame':    1801 obs. of  6 variables:
##  $ Date  : Factor w/ 1801 levels "2011-01-03","2011-01-04",..: 1801 1800 1799 1798 1797 1796 1795 1794 1793 1792 ...
##  $ Open  : num  224 225 225 226 225 ...
##  $ High  : num  228 226 226 226 228 ...
##  $ Low   : num  222 221 221 224 225 ...
##  $ Close : num  227 224 222 225 227 ...
##  $ Volume: int  6448117 7619247 10731921 10535437 9272078 16080436 29507056 7758149 10130508 10232257 ...
tw2330$Date = as.Date(tw2330$Date)

tw2330_2017 = tw2330[(tw2330$Date >= '2017-01-01' & tw2330$Date < '2018-01-01'),]
max(tw2330_2017$Close)
## [1] 244
summary(tw2330_2017$Close)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   179.5   191.5   212.5   210.1   221.5   244.0
ordered_stock = tw2330_2017[order(tw2330_2017$Close, decreasing = T),]

List

item= list(thing='hat',size=8.25)
item$thing
## [1] "hat"
item$size
## [1] 8.25
flower= list(title="iris dataset", data= iris)
class(flower)
## [1] "list"
class(flower$data)
## [1] "data.frame"
flower$data[1,"Sepal.Width"]
## [1] 3.5
setwd('~/lecture/riii')
tw2330 = read.csv("data/2330.csv", header=TRUE)
tw2330$Date = as.Date(tw2330$Date)
tw2330_2017 = tw2330[(tw2330$Date >= '2017-01-01' & tw2330$Date < '2018-01-01'),]
tw2330_2017
##           Date  Open  High   Low Close   Volume
## 77  2017-12-29 227.5 230.0 226.5 229.5  5723607
## 78  2017-12-28 226.5 228.0 225.0 226.0  5506635
## 79  2017-12-27 225.0 226.0 225.0 225.0  2820169
## 80  2017-12-26 229.0 229.0 225.0 226.0  3118538
## 81  2017-12-25 228.0 229.5 226.5 228.5  1045118
## 82  2017-12-22 225.0 227.5 224.0 227.5  4299892
## 83  2017-12-21 226.5 227.0 224.5 225.0  4184730
## 84  2017-12-20 225.0 225.5 223.5 224.5  5902066
## 85  2017-12-19 226.5 228.5 224.0 225.0  5802911
## 86  2017-12-18 227.0 228.0 226.5 227.0  3307388
## 87  2017-12-15 228.5 230.0 226.5 230.0  9758791
## 88  2017-12-14 228.0 230.5 227.5 230.5  3940387
## 89  2017-12-13 227.5 228.0 226.5 227.0  4068638
## 90  2017-12-12 229.5 229.5 225.0 227.5  4946469
## 91  2017-12-11 228.5 229.0 227.0 227.5  4706571
## 92  2017-12-08 231.0 231.0 224.5 227.0  8628368
## 93  2017-12-07 226.5 226.5 222.5 226.5  9287743
## 94  2017-12-06 228.0 229.5 226.5 227.0  7374198
## 95  2017-12-05 231.0 231.0 228.5 229.5  6815812
## 96  2017-12-04 232.5 234.5 231.0 234.0  5043085
## 97  2017-12-01 228.5 233.5 227.5 231.0  8622122
## 98  2017-11-30 226.5 230.5 226.0 226.0 24850555
## 99  2017-11-29 235.0 236.0 234.5 234.5  6052893
## 100 2017-11-28 234.5 235.0 233.0 234.0 10489525
## 101 2017-11-27 240.0 240.0 237.0 237.0  7696717
## 102 2017-11-24 242.0 244.5 241.5 244.0  2716320
## 103 2017-11-23 242.0 243.5 241.5 242.5  2268663
## 104 2017-11-22 244.5 244.5 242.0 242.0  6479608
## 105 2017-11-21 240.0 243.0 239.5 243.0  4958222
## 106 2017-11-20 241.0 241.5 238.0 238.5  3894916
## 107 2017-11-17 240.5 242.5 240.5 241.5  4512740
## 108 2017-11-16 238.0 240.0 237.5 238.0  3931192
## 109 2017-11-15 239.0 239.5 236.0 237.5  6826092
## 110 2017-11-14 241.0 241.0 239.0 240.0  4048826
## 111 2017-11-13 240.0 241.5 239.5 239.5  2904559
## 112 2017-11-10 240.0 242.0 239.5 240.5  3403155
## 113 2017-11-09 240.5 243.0 240.0 241.0  4898212
## 114 2017-11-08 243.0 243.5 242.0 242.5  3427043
## 115 2017-11-07 242.0 244.0 241.5 244.0  4904755
## 116 2017-11-06 243.5 244.0 239.0 239.5  5063647
## 117 2017-11-03 240.5 241.0 238.5 239.0  3955941
## 118 2017-11-02 242.0 242.5 240.5 241.0  3819659
## 119 2017-11-01 243.5 245.0 241.5 242.5  4957147
## 120 2017-10-31 243.5 245.0 241.5 243.0  5497063
## 121 2017-10-30 242.0 245.0 241.5 243.0  6760805
## 122 2017-10-27 237.5 240.0 237.5 239.0  4240754
## 123 2017-10-26 237.0 238.0 236.0 236.0  3069618
## 124 2017-10-25 238.5 239.0 237.5 238.0  4022067
## 125 2017-10-24 240.0 240.0 238.0 238.0  3573600
## 126 2017-10-23 239.0 240.0 238.5 239.0  3776142
## 127 2017-10-20 238.0 239.5 237.5 237.5  5900167
## 128 2017-10-19 239.5 241.5 239.0 239.0  5636769
## 129 2017-10-18 239.5 239.5 237.0 237.5  6881364
## 130 2017-10-17 238.0 238.0 235.0 235.5  4171891
## 131 2017-10-16 237.5 238.0 236.0 238.0  4738466
## 132 2017-10-13 237.5 237.5 234.5 237.5  5465540
## 133 2017-10-12 235.0 237.5 234.5 237.5 10028716
## 134 2017-10-11 226.5 233.5 226.5 233.0 14709173
## 135 2017-10-06 225.0 225.5 223.5 224.5  3515113
## 136 2017-10-05 222.0 225.5 222.0 224.5  5230963
## 137 2017-10-03 219.0 223.0 219.0 222.5  8131204
## 138 2017-10-02 219.5 220.5 218.5 220.5  6154603
## 139 2017-09-30 218.0 218.5 216.5 216.5   924824
## 140 2017-09-29 216.0 217.5 215.5 216.5  4627110
## 141 2017-09-28 215.0 216.0 213.5 214.0  6788535
## 142 2017-09-27 217.5 217.5 215.0 215.0  4876464
## 143 2017-09-26 217.5 218.0 214.0 214.0  4973702
## 144 2017-09-25 217.5 218.5 217.0 217.0  3671148
## 145 2017-09-22 221.5 222.0 218.5 218.5  4733578
## 146 2017-09-21 221.0 223.0 220.0 221.0  4125047
## 147 2017-09-20 221.0 222.0 220.0 221.5  4491615
## 148 2017-09-19 221.5 221.5 220.0 221.5  5178752
## 149 2017-09-18 219.0 220.0 218.0 219.5  3871213
## 150 2017-09-15 218.5 219.0 217.0 218.5  9719495
## 151 2017-09-14 218.5 219.0 217.5 218.5  4003999
## 152 2017-09-13 217.5 219.0 217.5 218.0  3829117
## 153 2017-09-12 219.0 219.5 217.5 219.0  4721715
## 154 2017-09-11 219.0 219.5 216.5 217.0  4136325
## 155 2017-09-08 217.0 218.0 216.5 218.0  5549520
## 156 2017-09-07 218.0 218.5 216.0 217.0  4156619
## 157 2017-09-06 216.5 218.0 216.0 217.0  3478129
## 158 2017-09-05 218.0 218.0 216.5 218.0  3775102
## 159 2017-09-04 216.5 218.0 215.5 217.5  3266564
## 160 2017-09-01 215.0 217.5 215.0 216.5  3851834
## 161 2017-08-31 217.5 218.0 215.5 216.5  5726389
## 162 2017-08-30 216.0 218.0 216.0 217.5  4274684
## 163 2017-08-29 216.0 216.0 215.0 216.0  3482959
## 164 2017-08-28 215.0 216.5 215.0 216.0  3288168
## 165 2017-08-25 217.5 217.5 216.0 217.5  2199920
## 166 2017-08-24 216.0 217.0 215.5 217.0  3297756
## 167 2017-08-23 215.5 216.0 214.0 215.5  2495749
## 168 2017-08-22 213.5 214.5 213.0 214.5  3042471
## 169 2017-08-21 212.5 213.0 211.5 211.5  2517036
## 170 2017-08-18 212.0 213.0 211.0 212.5  2908768
## 171 2017-08-17 213.5 214.0 213.0 214.0  1785167
## 172 2017-08-16 214.5 214.5 211.0 213.0  5354869
## 173 2017-08-15 213.0 214.5 213.0 214.0  2891655
## 174 2017-08-14 213.5 214.0 210.0 211.0  6216594
## 175 2017-08-11 211.0 213.5 210.5 212.5  8771492
## 176 2017-08-10 215.5 215.5 212.5 214.0  5621260
## 177 2017-08-09 215.0 215.5 213.5 214.5  6023018
## 178 2017-08-08 217.5 219.0 216.0 217.5  5467733
## 179 2017-08-07 213.5 216.5 213.5 216.0  4653777
## 180 2017-08-04 213.5 214.0 212.5 213.0  4664833
## 181 2017-08-03 213.0 214.0 212.5 213.5  5484489
## 182 2017-08-02 214.0 216.0 214.0 216.0  5892580
## 183 2017-08-01 212.5 214.0 212.0 212.0  4201150
## 184 2017-07-31 211.5 214.5 211.5 214.5  4277399
## 185 2017-07-28 213.0 214.0 212.5 213.0  4204292
## 186 2017-07-27 213.5 216.0 213.5 215.5  4958623
## 187 2017-07-26 215.0 215.0 212.5 213.0  3139704
## 188 2017-07-25 214.0 214.5 213.5 214.0  2861441
## 189 2017-07-24 213.5 214.5 213.0 214.5  4279712
## 190 2017-07-21 214.0 215.0 213.5 214.0  3225825
## 191 2017-07-20 215.0 215.5 214.0 215.5  4468109
## 192 2017-07-19 212.5 215.0 212.5 214.5  4428024
## 193 2017-07-18 213.0 214.0 212.0 214.0  3972325
## 194 2017-07-17 215.0 215.5 211.5 213.0  4566620
## 195 2017-07-14 213.0 214.5 212.0 213.0  4773890
## 196 2017-07-13 212.0 216.0 211.5 214.5 10735533
## 197 2017-07-12 211.0 212.5 210.5 210.5  5599902
## 198 2017-07-11 208.0 212.0 207.5 212.0  6987070
## 199 2017-07-10 206.5 207.0 206.0 206.0  2748069
## 200 2017-07-07 207.0 207.5 205.5 206.0  4266155
## 201 2017-07-06 208.0 208.5 207.0 207.5  3166474
## 202 2017-07-05 207.0 208.5 206.5 208.5  4834795
## 203 2017-07-04 208.0 208.5 207.0 207.0  4387234
## 204 2017-07-03 207.5 209.0 207.0 209.0  3968236
## 205 2017-06-30 206.5 208.5 206.5 208.5  6410542
## 206 2017-06-29 210.5 210.5 208.5 210.0  5468672
## 207 2017-06-28 209.5 210.0 208.0 208.5 10154360
## 208 2017-06-27 214.0 214.0 211.0 211.5  9171063
## 209 2017-06-26 212.0 215.0 212.0 215.0 12551539
## 210 2017-06-23 218.0 218.5 217.0 217.0  8627394
## 211 2017-06-22 217.0 218.0 216.5 218.0  5268473
## 212 2017-06-21 216.0 217.0 214.5 215.5  9673307
## 213 2017-06-20 215.0 218.0 214.5 216.5  6208332
## 214 2017-06-19 211.0 213.0 210.5 213.0  3325299
## 215 2017-06-16 207.5 212.0 207.0 211.5  6902455
## 216 2017-06-15 207.5 208.0 207.0 208.0  3688793
## 217 2017-06-14 208.5 209.5 206.0 207.0  7539029
## 218 2017-06-13 207.0 208.5 206.5 208.0  9059507
## 219 2017-06-12 207.0 210.0 207.0 207.5 12130952
## 220 2017-06-09 214.5 215.0 212.0 212.0  6786964
## 221 2017-06-08 212.0 213.0 211.5 213.0  3925733
## 222 2017-06-07 212.0 212.5 210.0 211.5  6248819
## 223 2017-06-06 210.5 211.5 210.5 210.5  3152347
## 224 2017-06-05 209.5 212.0 209.0 212.0  4537970
## 225 2017-06-03 209.0 209.0 208.0 209.0   320349
## 226 2017-06-02 208.5 209.0 207.5 209.0  4712487
## 227 2017-06-01 205.0 207.0 204.5 207.0  5686362
## 228 2017-05-31 206.5 207.0 203.0 203.0 13766457
## 229 2017-05-26 205.0 207.0 205.0 207.0  6708824
## 230 2017-05-25 206.0 207.0 205.5 207.0  4619837
## 231 2017-05-24 205.0 206.0 205.0 205.5  2753669
## 232 2017-05-23 205.0 207.0 204.5 205.0  4120476
## 233 2017-05-22 203.5 205.0 203.0 205.0  2809108
## 234 2017-05-19 203.5 204.5 202.5 203.0  3358910
## 235 2017-05-18 202.5 204.0 201.5 203.5  4551204
## 236 2017-05-17 203.0 204.0 203.0 204.0  4396486
## 237 2017-05-16 205.0 205.0 203.5 204.5  6775942
## 238 2017-05-15 204.0 206.0 204.0 206.0  5282547
## 239 2017-05-12 205.0 207.0 205.0 206.0  5155193
## 240 2017-05-11 204.5 208.5 204.0 207.5  9022070
## 241 2017-05-10 204.0 206.0 204.0 205.5  5816264
## 242 2017-05-09 205.5 207.0 203.5 203.5  9895582
## 243 2017-05-08 199.0 202.5 199.0 202.5  7344706
## 244 2017-05-05 197.0 198.5 197.0 197.5  3374189
## 245 2017-05-04 198.5 199.0 197.0 198.0  4379194
## 246 2017-05-03 198.0 198.5 197.0 198.0  5085817
## 247 2017-05-02 198.5 199.0 195.5 196.5  8720371
## 248 2017-04-28 193.5 194.5 193.0 194.5  6767652
## 249 2017-04-27 192.0 193.0 190.5 193.0  5370409
## 250 2017-04-26 192.0 192.0 190.5 191.0  5724562
## 251 2017-04-25 190.5 192.0 189.5 192.0  6096632
## 252 2017-04-24 191.0 191.5 188.5 190.0  3671218
## 253 2017-04-21 187.5 190.0 187.5 190.0  3291008
## 254 2017-04-20 186.5 188.0 186.5 187.0  4023644
## 255 2017-04-19 187.5 187.5 186.5 186.5  5701084
## 256 2017-04-18 188.0 189.5 187.5 188.0  4723015
## 257 2017-04-17 189.0 189.0 187.5 187.5  3223518
## 258 2017-04-14 189.5 189.5 188.0 189.0  5796262
## 259 2017-04-13 189.5 192.0 189.5 191.5  2829915
## 260 2017-04-12 190.5 191.5 190.0 191.0  3299859
## 261 2017-04-11 190.0 191.0 189.0 191.0  1609247
## 262 2017-04-10 191.0 191.5 189.5 190.0  3241252
## 263 2017-04-07 192.0 192.0 188.5 191.0  3597927
## 264 2017-04-06 193.0 193.0 191.0 191.5  3102751
## 265 2017-04-05 189.5 193.0 189.5 193.0  8398904
## 266 2017-03-31 191.0 192.0 189.0 189.0  6392159
## 267 2017-03-30 192.5 193.0 190.5 191.5  5426010
## 268 2017-03-29 194.5 194.5 191.0 191.5  6417196
## 269 2017-03-28 195.0 195.0 192.5 194.5  7414953
## 270 2017-03-27 194.5 194.5 192.0 193.0  5650553
## 271 2017-03-24 192.0 193.0 192.0 192.5  3377633
## 272 2017-03-23 192.0 193.5 192.0 193.5  3563469
## 273 2017-03-22 192.5 193.5 191.5 193.5  5285527
## 274 2017-03-21 192.0 195.0 191.5 195.0  6264274
## 275 2017-03-20 191.5 191.5 189.5 191.5  3099321
## 276 2017-03-17 189.5 191.5 189.0 191.5  6448133
## 277 2017-03-16 188.0 190.0 188.0 190.0  5969583
## 278 2017-03-15 185.5 187.0 185.5 186.5  2634475
## 279 2017-03-14 188.0 188.0 186.0 186.0  4168861
## 280 2017-03-13 185.0 186.5 185.0 186.5  1952063
## 281 2017-03-10 184.0 184.5 183.0 183.5  3685002
## 282 2017-03-09 185.5 186.0 184.0 184.5  5265575
## 283 2017-03-08 186.0 188.0 185.5 187.0  5941049
## 284 2017-03-07 184.0 185.5 184.0 185.5  3480059
## 285 2017-03-06 184.0 184.5 183.5 183.5  2305447
## 286 2017-03-03 184.5 185.0 184.0 184.0  5199921
## 287 2017-03-02 188.0 188.5 185.0 186.0  7440731
## 288 2017-03-01 188.5 188.5 186.0 186.0  8657853
## 289 2017-02-24 187.5 190.5 187.5 189.0  4305777
## 290 2017-02-23 188.0 189.5 187.0 188.5  6743656
## 291 2017-02-22 190.5 191.0 188.5 188.5  4857363
## 292 2017-02-21 190.0 190.0 188.5 190.0  5904949
## 293 2017-02-20 190.0 190.5 189.5 190.0  2518027
## 294 2017-02-18 190.0 190.5 189.5 189.5   667393
## 295 2017-02-17 190.0 190.5 189.0 189.5  3870482
## 296 2017-02-16 190.0 190.5 188.0 189.0  5110006
## 297 2017-02-15 187.0 189.5 186.5 189.0  7424698
## 298 2017-02-14 189.0 190.0 187.5 187.5  8612016
## 299 2017-02-13 186.5 188.0 186.5 187.5  4716929
## 300 2017-02-10 184.5 185.5 184.0 185.5  6433740
## 301 2017-02-09 184.0 185.5 183.5 184.0  3503839
## 302 2017-02-08 183.5 184.5 183.0 183.5  5356341
## 303 2017-02-07 183.5 185.0 183.0 184.5  4355676
## 304 2017-02-06 184.5 185.5 184.0 184.5  4574432
## 305 2017-02-03 186.0 186.0 183.5 184.5  5447525
## 306 2017-02-02 188.0 188.5 184.0 184.5 17555417
## 307 2017-01-24 185.0 186.5 184.5 185.5 10213453
## 308 2017-01-23 182.5 185.0 182.5 185.0  6801283
## 309 2017-01-20 181.0 181.5 180.5 181.0  4243817
## 310 2017-01-19 179.5 181.0 179.5 180.5  4440069
## 311 2017-01-18 180.5 181.0 179.5 181.0  4274442
## 312 2017-01-17 180.5 181.0 179.5 181.0  2380060
## 313 2017-01-16 180.0 180.5 179.0 179.5  5527552
## 314 2017-01-13 180.5 182.5 180.5 181.5  9492277
## 315 2017-01-12 182.5 185.5 182.5 184.5  7589227
## 316 2017-01-11 185.0 185.0 181.5 182.0  5324808
## 317 2017-01-10 184.5 185.5 183.5 184.0  3724356
## 318 2017-01-09 184.0 185.0 183.0 184.0  3419409
## 319 2017-01-06 184.0 184.5 183.5 184.0  4130047
## 320 2017-01-05 182.0 183.5 181.5 183.5  3843843
## 321 2017-01-04 183.0 184.0 181.5 183.0  4460200
## 322 2017-01-03 181.5 183.5 181.0 183.0  4135245
save(tw2330_2017,file="2330_2017.RData")
rm(tw2330_2017)
load("2330_2017.RData")