Please submit this homework as an R Markdown (Rmd) file.
As I mentioned during our first meeting, rmarkdown is a way to incorporate text, with simple formatting, with R code chunks. Rather than spell out how to create an Rmd file here, I recommend you consult the following resources:
[last name]_ENS623_SP18_PS1.Rmd
For example,
Lammens_ENS623_SP18_PS1.Rmd
Problems 1-3 are each worth 5 points, Problem 4 is worth 10.
Using the help features in R, i.e. preface a function with ?
, look up how to use the matrix
function. Create two different matrices that match those presented below.
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 7 8 9
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
## [3,] 3 6 9
In R, you can access individual elements of a vector, matrix, data frame, etc. using the square brackets, []
. In the example below, I create a vector of pets, and access individual and sets of elements.
# Create my pets vector
pets <- c("cat", "dog", "rabbit", "pig", "snake")
# Access the first elemetn
pets[1]
## [1] "cat"
# Access multiple elements, in sequence
pets[3:4]
## [1] "rabbit" "pig"
# Access multiple elements, out of sequence
pets[c(1,4)]
## [1] "cat" "pig"
Use this knowledge regarding accessing elements to reverse the order of the pets
vector.
You can access elements of a matrix using row, column notation. For example, below I access the middle element of Matrix 1 above.
matrix_1[2,2]
## [1] 5
Use this to make a new 2-row by 2-column matrix comprised of elements from Matrix 1
Re-assign the center value of the matrix to a value of 99.
Read Chapter 1 of How to do Ecology and skim the Sutherland et al. 2013 paper (both posted on BlackBoard). In less than 250 words, respond to these readings. Some prompts that might help you in your response (though you are not obliged to use these) -