-
Notifications
You must be signed in to change notification settings - Fork 1
/
exercise3.Rmd
124 lines (88 loc) · 1.99 KB
/
exercise3.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
## Exercise 3. Character vector manipulation (10 minutes)
Create the script "exercise3.R" and save it to the "Rcourse/Module1" directory: you will save all the commands of exercise 3 in that script.
<br>Remember you can comment the code using #.
**1- Go to Rcourse/Module1
First check where you currently are with getwd();
then go to Rcourse/Module1 with setwd()**
<details>
<summary>
*Answer*
</summary>
```{r, eval=F}
getwd()
setwd("Rcourse/Module1")
setwd("~/Rcourse/Module1")
```
</details>
**2- Create vector w as:**
```{r}
w <- rep(x=c("miRNA", "mRNA"), times=c(3, 2))
```
**3- View vector w in the console: how does function rep() work ?**
<br>Play with the **times** argument.
<details>
<summary>
*Answer*
</summary>
```{r}
rep(x=c("miRNA", "mRNA"), times=c(3, 4))
rep(x=c("miRNA", "mRNA"), times=c(10, 2))
```
</details>
**4- What is the output of table(w) ? What does the table function do ?**
**5- Type w[grep(pattern="mRNA", x=w)] and w[w == "mRNA"]**
<br> Is there a difference between the two outputs?
<details>
<summary>
*Answer*
</summary>
```{r}
w[grep(pattern="mRNA", w)]
w[w == "mRNA"]
# no difference between the outputs
```
</details>
**6- Now type w[grep(pattern="RNA", w)] and w[w == "RNA"]**
<br> Is there a difference between the two outputs?
<details>
<summary>
*Answer*
</summary>
```{r}
w[grep(pattern="RNA", w)]
w[w == "RNA"]
# grep outputs 5 values but == outputs none
```
</details>
What is the difference between **==** and **grep** ?
<details>
<summary>
*Answer*
</summary>
>= looks for exact matches.
<br>
grep looks for **patterns**.
</details>
**7- Create vector g as:**
```{r}
g <- c("hsa-let-7a", "hsa-mir-1", "CLC", "DKK1", "LPA")
```
How many elements do w and g contain?
<details>
<summary>
*Answer*
</summary>
```{r}
length(w); length(g)
```
</details>
**8- Name the elements of g using the elements of w.**<br>
(i.e. the names of each element of g will be the elements of w).
<details>
<summary>
*Answer*
</summary>
```{r}
names(g) <- w
```
</details>