forked from Seike1223/lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek2_note.Rmd
104 lines (64 loc) · 1.64 KB
/
week2_note.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
title: "Week.2"
output: html_notebook
---
# Introduction to R
R as a programming language.
# Getting started with R in a few steps
- try out the console
## Arithmetrics with R
- Basic arithmetic operations:`+` (addition), `-` (substraction), `*` (multiplication), `/` (division), `^` (exponentiation)
```{r}
3+5
14/2
```
- Basic arithmetic **functions**
- logarithmus and exponentials: `log2(x), log10(x), exp(x)`
- Others: `abs(x)`, `sqrt(x)`
```{r}
log2(6)
sqrt(36)
```
> Getting help
```{r}
?sqrt
```
## Parameter (參數) 與 Argument (引數).
- argument: 【呼叫者】傳給【被呼叫者】的「值」(value)
- parameter: 【被呼叫者】用來接收【呼叫者】傳來引數的「變數」(variable)
自然語言亂入:`欸()`, `叫(x, num, pitch)`.
> `叫(啊, num = 3, pitch = 'high')`
```{r}
head(cars, n=10)
```
# Data types
- Basic *data types*: **numeric, character, logical**
- Supported *data structure*: **vector, matrix, factor, data frame**
# Variable and value assignment 變數與賦值 `<-`
```{r}
# numeric variable
my_age <- 40
# character variable
my_name <- "shukai"
# logical variable (e.g., are you a student?) y/n
is_student <- TRUE
```
# Install packages
```{r}
#install.packages("tidyverse")
```
```{r}
#install.packages(c("quantmod", "dygraphs"))
```
```{r}
library(quantmod)
library(dygraphs)
```
- Let's check Google stock since the 2008
```{r}
g_stock_prices <- getSymbols("GOOG", src = "yahoo", from = "2008-01-01", auto.assign = FALSE)
chartSeries(g_stock_prices)
```
```{r}
dygraph(g_stock_prices[,c("GOOG.Close")], main = "Google Stock Price Starting in 2008")
```