generated from karthik/binder-test
/
exercises-1.R
37 lines (25 loc) · 855 Bytes
/
exercises-1.R
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
## This document takes you through some of the R code we covered in the slides with
## additional exercises for you to complete on your own.
## Exercises are prefaced with a single # so make sure to fill in the document
## with your answers!
## Load and view data
load(file = "dat.rda")
dat
# What are the dimensions of this matrix?
# Find one (or more!) R functions to answer that question
# (via Google, a friend/neighbor, prior knowledge)
# Answer:
## Select a scalar
dat[3, 4]
# Try to produce an error message : "subscript out of bounds"
# Answer:
## Select a vector
dat[, 4]
# Find another way(s) to select the "yob" vector
# (There's a hint in the question!)
# Answer:
## Transpose a matrix
t(dat) # to view
dat_t <- t(dat) # to store as a new object
# What are the dimensions of dat_t (and the code to answer that question)?
# Answer: