## 7.4 Exercice 1. Getting started ~ 15 minutes

Create the script “exercise1.R” (in R Studio: File -> New File) and save it to the “Rcourse/Module1” directory: you will save all the commands of exercise 1 in that script.
Remember you can comment the code using #.

1- From the console, go to Rcourse/Module1. First check where you currently are with getwd(); then go to Rcourse/Module1 with setwd()

correction

``````getwd()
setwd("Rcourse/Module1")
setwd("~/Rcourse/Module1")``````

2- Using R as a calculator, calculate the square root of 654 (don’t know the function? Search the internet!).

correction

``sqrt(654)``
``##  25.57342``

3- Using R as a calculator, calculate the percentage of males and females currently present in the classroom.

correction

``````# 6 males out of 19 students:
(6/19) * 100``````
``##  31.57895``
``````# 13 females out of 19 students
(13/19) * 100``````
``##  68.42105``

4- Create a new object “myobject” with value 60. Show “myobject” in the console.

correction

``````myobject <- 60
myobject``````
``##  60``

5- Reassign myobject with value 87.

correction

``myobject <- 87``

6- Subtract 1 to myobject. Reassign.

correction

``myobject <- myobject - 1``

7- Create a new object “mysqrt” that will store the square root of “myobject”.

correction

``mysqrt <- sqrt(myobject)``

8- Create a new object “mydiv” that will store the result of “myobject” divided by “mysqrt”.

correction

``mydiv <- myobject / mysqrt``