Assignment 01: base R, command line, & Git(Hub)

Download the .Rmd file here.

To submit this assignment, upload the full document, including the original questions, your code, and the output. Submit your assignment as a knitted .pdf. Please ensure the text on your .pdf does not continue past the end of the page. If you use code chunks to write your answers to the command line questions, check that the code chunk headers say eval=FALSE so RStudio doesn’t try to run them when knitting (the example code chunks provided for questions 4 and 5 include this).

1. Variable assignment (1 mark)

  1. Assign the value 5 to the variable/object a. Display a. (0.25 marks)
  1. Assign the result of 10/3 to the variable b. Display b. (0.25 marks)
  1. Write a function that adds two numbers and returns their sum. Use it to assign the sum of a and b to result. Display result. (In practice, there is already a more sophisticated built-in function for this: result <- sum(a, b)) (0.25 marks)
  1. Write a function that multiplies two numbers and returns their product. Use it to assign the product of a and b to product. Display product. (In practice, there is already a more sophisticated built-in function for this: product <- prod(a, b)) (0.25 marks)

2. Vectors (2.5 marks)

  1. Create a vector v with all integers 0-30, and a vector w with every third integer in the same range. (0.25 marks)
  1. What is the difference in lengths of the vectors v and w? (0.25 marks)
  1. Create a new vector, v_square, with the square of elements at indices 3, 6, 7, 10, 15, 22, 23, 24, and 30 from the variable v. Hint: Use indexing rather than a for loop. (0.25 marks)
  1. Calculate the mean and median of the first five values from v_square. (0.25 marks)
  1. Create a boolean vector v_bool, indicating which vector v elements are bigger than 20. How many values are over 20? Hint: In R, TRUE = 1, and FALSE = 0, so you can use simple arithmetic to find this out. (0.5 marks)
  1. Write a function that calculates the median of the last two elements of any numeric vector. Test this function with the v and v_square vectors. (1 marks)

3. Data frames (1.5 marks)

  1. There are many built-in data frames in R, which you can find more details about online. What are the column names of the built-in dataframe beaver1? How many observations (rows) and variables (columns) are there? (0.5 marks)
  1. Display both the first 6 and last 6 rows of this data frame. Show how to do so with both indexing as well as specialized functions. (0.5 marks)
# With indexing


# With functions
  1. What is the min, mean, and max body temperature for beavers inside and outside of the retreat? Hint: You can use ? on the beaver1 data set to get more information about it. Remember that each column in a data frame is a vector and you can use the same functions. (0.5 marks)

4. Command line (1 mark)

What commands would you run to create a directory named “mydir”, check mydir’s permissions, add write permissions for users, copy mydir to “mydir2” , and then remove mydir? Hint: try running each step in your terminal to check if the output is what you expect (1 mark)

5. Understanding command line software (1 mark)

Open the documentation for Earl Grey, a software programme that identifies transposable elements in genomes. There may be a lot of unfamilliar terms on this web page, but we’ll just be skimming this page to practice identifying the kind of information command line software might require and how to provide that.

  1. What three arguments (files/information) are required input for this software? (0.3 marks)

  2. What would you type into the command line to provide Earl Grey with those minimum command options? You don’t need to make up example text for this, just ensure you have the three - arguments written out. Hint: search for “minimum command options” on the GitHub page and use the next line (0.3 marks)

  3. Based on the visual overview of the software (or the “Example Outputs” section) on the GitHub page, what does this software output? (0.2 marks)

  4. What optional parameter (i.e. the - argument) does Earl Grey offer to display help information? Is this kind of help parameter common? Hint: you can search for “help documentation” in your lecture notes (0.2 marks)

6. GitHub (1 mark)

  1. Make a Github account. You can do this at github.com. What is your GitHub username? (1 mark)