-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntroduction_to_R.Rmd
184 lines (126 loc) · 3.82 KB
/
Introduction_to_R.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
title: "Introduction to R"
author: "Chunlei Ge"
date: '2023-01-24'
output:
pdf_document:
toc: yes
fig_height: 6
fig_width: 10
number_sections: yes
html_document:
theme: united
toc: true
toc_float: no
number_sections: true
highlight: tango
fig_width: 10
fig_height: 8
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Learning objectives
- How to install R and Rstudio
- How to load an R package
- How to use RStudio cloud server
- How to update them
- How to run some simple calculation
# R and Rstudio
## Download and install R
### Windows
Visit [\textcolor{blue}{R Project}](https://www.r-project.org/) to learn about R versions
Download and install R from your preferred CRAN mirror [\textcolor{blue}{here}](https://cran.r-project.org/mirrors.html)
Choose “0-Cloud” or a mirror site near you
### Mac
Check that your macOS system is up-to-date
Download and install R from [\textcolor{blue}{R Archive Network}](https://cran.r-project.org/)
### Linux
Download R for Linux <https://mirror.rcg.sfu.ca/mirror/CRAN/>
## Download and install R studio IDE (Windows and Mac)
Download and install R Studio from [\textcolor{blue}{here}](https://www.rstudio.com/products/rstudio/download/#download)
## R Markdown
R Markdown is a format for writing reproducible, dynamic reports with R.
R Markdown document can help us generate PDF, HTML, and other types of output with R code, results, and raw LaTeX.
(This pdf file <Introduction_to_R.pdf> is the output of Rmarkdown file <Introduction_to_R.Rmd>.
Feel free to open and edit it after you install Rstudio in your computer or use it as the template of your first report)
Learn more at https://rmarkdown.rstudio.com/
And a quick way to familiar with R Markdown https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf
Some more about R studio: https://www.rstudio.com/resources/cheatsheets/
## Load R package
use function: $install.packages()$ to installing a package installing a Java Version : <https://www.java.com/en/download/>
```{r eval=FALSE}
install.packages("MASS")
install.packages("rJava")
install.packages("RWeka")
```
Help
```{r}
help (pi)
?pi
# the mathematical functions ...
?Arithmetic
?abs
?log
?round
?sin
?Special
```
\
Loading an R package
```{r}
library(MASS)
library(rJava)
library(RWeka)
```
## How to use RStudio cloud
<https://rstudio.cloud/>
## How to update
### Updating R
Windows\
First Install the $installr$ package if you don't have it
```{r}
# installing/loading the package:
if(!require(installr)) {
install.packages("installr");
require(installr)
} #load / install+load installr
```
Now call $updateR()$ function to call update
```{r eval=FALSE}
updateR()
```
\
macOS\
One Mac you need to go to the CRAN website to install the newer package installer.
### Updating RStudio
Updating RStudio is easy, just go to $Help$ \> $Check\ for\ Updates$ to install newer version.
### Updating R package
Updating out of date package that were installed with $install.packages()$is easy with the $update.packages()$ function.
```{r eval=FALSE}
update.packages("MASS")
```
# Simple calculation
```{r}
x <- c(67,67,77,62,69.84,74.168,29.5,81.8,71,71,74.8)
y <- c(170,176,172,183,167.64,175.26,165.1,177.8,170,178,176)
y^2
y+2
y/2
x+2
x*x
2*x
x^2
log(x)
```
# Reference
Data Analysis in R. https://ubc-library-rc.github.io/data-analysis-r/
\center{**
Keep Calm and Have a Cup of Tea**}
![tea](C:/Users/ivyge/Downloads/tea.png)
\center{image: https://www.expertreviews.co.uk/food-drink/1415799/best-green-tea}