-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRbasics.Rmd
74 lines (53 loc) · 1.45 KB
/
Rbasics.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
# R basics
## Arithmetic operators
| Operator | Function |
|:--------: |:-------------:|
| + | addition |
| - | subtraction |
| / | division |
| * | multiplication|
| ^ or ** | exponential |
In the R terminal:
```{r}
10 - 2
```
Type **Enter** for R to interpret the command.
## Simple calculations
Given the following table:
| type of RNA | Total |
| :---------: |:-------:|
| mRNA | 329 |
| miRNA | 45 |
| snoRNA | 12 |
| lncRNA | 28 |
Calculate the total number of RNAs reported in the table:
```{r}
329 + 45 + 12 + 28
```
What is the percentage of miRNA?
```{r}
( 45 / 414 ) * 100
```
## Objects in R
Everything that stores any kind of data in R is an **object**:
<img src="images/objects_box.png" alt="rstudio logo" width="300"/>
#R syntax
<img src="images/rsyntax1.png" alt="rstudio logo" width="350"/>
## Assignment operators
+ **<-** or **=**
+ Essentially the same but, to avoid confusions:
+ Use **<-** for assignments
+ Keep **=** for functions arguments
## Assigning data to an object
* Assigning a value to the object **B**:
B <- 10
* Reassigning: modifying the content of an object:
```{r, eval=FALSE}
B + 10
```
<span style="color:red">**B unchanged !!**</span><br>
```{r, eval=FALSE}
B <- B + 10
```
<span style="color:red">**B changed !!**</span><br>
* You can see the objects you created in the upper right panel in RStudio: the environment.