Individual Assignment - Data Camp Intro
to Quantitative Ecology:
The objectives for this assignment are to learn some R fundamentals, including:
Hint: you should read through the template R-script before you complete the DataCamp course. It will be helpful to work on the questions in the script as you complete the corresponding sections in the DataCamp assignment.
Follow the DataCamp invite link and complete the Introduction to R course that is assigned to you.
Create an R script to work through the questions at the end of this page.
Your final R-script will be graded on whether the code runs, is correct, and your comments.
Comments are lines within an R-script that begin with the number sign, or hash symbol: #
When r executes code in your script, it ignores all of the text on a line following the comment character.
Here is an example of how it works:
# I am going to add two numbers together, and then multiply the sum:
(4 + 8) * 2
## [1] 24
# This is what I tried to do first, but it didn't work:
# 4 + 8) * 2
Notice that R ignored the comment lines, and performed the calculation on the uncommented line.
Comments are an important form of documentation.
Good comments allow you, or someone else, to understand what the code itself is doing. The explain both what the objective of the code is, and important technical details of how the code itself works.
You’ll find that uncommented scripts can be difficult or impossible to read or understand. Uncommented code is a lot like data without metadata!
You must upload an R script that includes answers to the following questions
the R script you submit must be neatly formatted and your code answer to every question must be accompanied by corresponding code comments that briefly explain what your code accomplishes.
Q1 (2 pts.): Create a logical variable called ‘aaa’ that holds a value of TRUE.
Q2 (2 pts.): Create a two numeric variables called ‘one’ and ‘four’.
Q3 (2 pts.): Create a vector called
vec_1
that contains a sequence of integers from 1 to
10.
Q4 (2 pts.): Create a vector called
vec_2
that contains values that are three times the values
of the elements of vec_1
.
Q5 (2 pts.): Create a vector called
vec_3
whose elements are the product of the corresponding
elements in vec_1
and vec_2
.
Q6 (2 pts.): Create a vector called
vec_4
whose elements are the integers from 1 to
12.
Re-create the data frame planets_df from the DataCamp course.
Q9 (2 pts.): Extract the ‘rotation’ column from
planets_df and save it to a vector called rot
Q10 (2 pts.): Extract the value of planets_df in
row 2, column 3 and save it to a variable called
var_1
Q11 (2 pts.): Extract the even-numbered rows of planets_df and save them to a new data frame called planets_2