These exercises are about the vector sections of Introduction to R.
Exercise 1
## [1] 1 2 3 4 5
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
## [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## [91] 91 92 93 94 95 96 97 98 99 100
## [1] 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36
## [19] 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72
## [37] 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108
## [55] 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144
## [73] 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180
## [91] 182 184 186 188 190 192 194 196 198 200
## [1] 0 5 10 15 20
## Help on topic 'rep' was found in the following packages:
##
## Package Library
## base /usr/local/lib/R/library
## S4Vectors /usr/local/lib/R/host-site-library
##
##
## Using the first match ...
## [1] 1 1 2 2 3 3
## [1] 1 1 5 7 9 10
Exercise 2
## [1] 1 2 3 4 5 6 7 8 9 10
## [1] 2 3 4 5 6 7 8 9
## [1] 1 3 4 6 7 8 9 10
## [1] 2.449490 2.645751
## [1] 1 3 5 7 9
Exercise 3
## Help on topic 'paste' was found in the following packages:
##
## Package Library
## base /usr/local/lib/R/library
## BiocGenerics /usr/local/lib/R/host-site-library
##
##
## Using the first match ...
## [1] "A B"
## [1] "A_B"
Exercise 4
my_genes <- c("PKM", "ADPRH", "TDG", "ATP4A", "SLC6A4", "CAPN3", "TDG", "ATP1A2","PKM")
my_genes <- unique(my_genes)
my_genes
## [1] "PKM" "ADPRH" "TDG" "ATP4A" "SLC6A4" "CAPN3" "ATP1A2"
my_genes_of_interest <- c("SLC6A4", "CAPN3", "TDG", "ATP1A2", "IMPA1", "PDXK")
idx <- my_genes %in% my_genes_of_interest
idx
## [1] FALSE FALSE TRUE FALSE TRUE TRUE TRUE
## [1] "TDG" "SLC6A4" "CAPN3" "ATP1A2"
my_genes_of_interest <- c("SLC6A4", "CAPN3", "TDG", "ATP1A2", "IMPA1", "PDXK")
idx <- my_genes %in% my_genes_of_interest
idx
## [1] FALSE FALSE TRUE FALSE TRUE TRUE TRUE
## [1] "TDG" "SLC6A4" "CAPN3" "ATP1A2"
my_genes <- c("SMC1", "SMC3", "SCC1", "SCC3", "RAD21", "NIPBL", "SMC2", "SMC4","CAPH","CAPD3")
my_genes[grepl("SMC",my_genes)]
## [1] "SMC1" "SMC3" "SMC2" "SMC4"
Exercise 5
geneNames <- c("Gene_1", "Gene_2", "Gene_3","Gene_4")
expression <- c(1000, 3000, 10000, 12000)
geneLengths <- c(100, 3000, 200, 1000)
names(expression) <- geneNames
names(geneLengths) <- geneNames
expression
## Gene_1 Gene_2 Gene_3 Gene_4
## 1000 3000 10000 12000
## Gene_1 Gene_2 Gene_3 Gene_4
## 100 3000 200 1000
## [1] "Gene_2"
## [1] "Gene_2"
## [1] "Gene_4"
## Gene_1 Gene_2 Gene_3 Gene_4
## 10 1 50 12
## [1] "Gene_3"