Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

R

Views: 4030
Kernel: R (R-Project)

© Copyright 2016 Dr Marta Milo and Dr Mike Croucher, University of Sheffield.

Week 1 Practical

This Notebook contains practical assignments for Week 1.

It contains guidance on how to perform some comands in R along with practical tasks that you will have to implement yourself. You are free to base your work on the examples given here but you are also welcome to use different methods if you prefer. You will need to add descriptions of what you have done in the assigned tasks and a comment on the results obtained using Markdown cells.

You will need to create a new notebook in the Week 1 folder of your SageMathCloud account that you will call your username_week1.ipynb. The notebooks will be self-marked following a set of guidelines that you will receive with a notebook that containes the solutions to the exercises. THIS IS FORMATIVE FEEDBACK that you can use to improve your coding skills.

The last version of your notebook saved by the deadlines indicated on the module website will be the one that will be considered for self-marking. It will be moved in your assigment folder where you will find the guidelines and the solved notebook.

All the notebooks are meant to be used interactively. All the code needs to be written into code cells -- these are cells that can be executed by an R kernel. The outputs are not present in this notebook, but the code cells are executable.

You can access each code cell for editing by clicking into it and pressing SHIFT and ENTER simultaneously to execute the code. You can run all code cells at once by clicking on Cell in the above menu bar and choose Run All.

Basic operation in R

R is based on packages that become active when you call them into your workspace using the function library(my_package). In this practical we will not need to use packages that are not already loaded into your workspace, but it is useful to explore what is available and how to get help from R.

There are many ways to get help from R. Find out what the function library() does by using the commands help(library) or ?library.

Exercise 0: Create a notebook called your_username_week1.ipynb in the Week 1 folder.

Exercise 1: In your notebook called your_username_week1.ipynb, open a code cell execute the command library() results in. What happens if you type library without parentheses? Write a description of what you've discovered in a Markdown cell

Changing path and verifying location of workspace

You can verify where your current working directory is by using

getwd()

The result from the above command will include a very long path such as /projects/81b488df-6f86-4914-a3a2-03e1fb248f11/ which is a code that details exactly where you are in the SageMathCloud. This is your home directory. Your home directory will be in different locations depending on the system you are using -- SageMathCloud, your laptop or perhaps Sheffield's supercomputer.

You never need to remember the long code. Instead, you use the form ~/ to refer to your home directory. That is the string ~/Autum2016 refers to the Autumn2016 directory inside your home directory - wherever that home directory may be on the system you are using.

You can set your working directory using the command setwd(). For example if you want to move to the directory ~/Autumn2016 you can type:

setwd("~/Autumn2016")