Assignment: Hello R
This worksheet introduces you to R, R scripts and R markdown. Your submission will be pushed to your class repository at GitHub. After completion you should have gained some experience in running R commands within scripts, R markdown for running code and documentation within one file and Git/GitHub.
Things you need for this worksheet
- R — the interpreter can be installed on any operation system.
- RStudio — we recommend to use R Studio for (interactive) programming with R.
- Git environment for your operating system. For Windows users with little experience on the command line we recommend GitHub Desktop.
Hello R and GitHub submission
Please write an R script as an Rmd file with html output for the following task and commit it to your GitHub-based learning log:
- Assign the value of five to a variable called
a
and the value of two to a variable calledb
. - Compute the sum, difference, product and ratio of a and b (a always in the first place) and store the results to four different variables called
r1
,r2
,r3
, andr4
. - Create a vector
v1
which contains the values stored within the four variables from step 2. - Add a fifth entry to vector
v1
which representsa
by the power ofb
(i.e.a**b
). - Show the content of vector
v1
(e.g. use theprint
function or just type the variable name in a separate row). - Create a second vector
v2
which contains information on the type of mathematical operation used to derive the five results. Hence this vector should have five entries of values sum, difference,… - Show the content of vector
v2
. - Combine the two vectors
v1
andv2
into a data frame calleddf
. Each vector should become one column of the data frame so you will end up with a data frame having 5 rows and 2 columns. - Make sure that the column with the data of
v1
is named Results andv2
is named Operation. - Show the entire content of
df
. - Show just the entry of the cell in the second row and first column.
Create an HTML file from your Rmd file by knitting it. Then upload both files to Ilias. See here for where exactly to place your files as well as for the file naming conventions.