Exercise 1

These exercises accompany the Introduction to R tutorial.

Tip: You should write all of your script in the script editor (box in upper left hand corner) and then execute the code by hitting the “Run” button or using Ctrl + R.

  1. multiply 4 by 7
  2. raise 6 to the power of 3
  3. Subtract 1.5 from 10 and then raise the answer to the power of 1.3 plus 1.789
  4. Divide 5 by 2.5 then divide the answer by 4
  5. Create an object called “obj1” which is the number 15
  6. Create an object called “obj2”" which is the answer to the sum of 100 + 25
  7. Multiply “obj1” and “obj2” together and store the answer as another object called “obj3”
  8. Subtract 1 from “obj3” and calculate the 4th root (raise to power of 1/4). Save this as an object called “final.answer”
  9. Highlight and run “final.answer” to print your answer to the console
  10. Create a vector called “my.text”" which contains two elements, the phrases “Learning R” and “is fun!”. Highlight and run the my.text variable so it prints to your console.
  11. If you haven’t already done so, save the R script file to your thumb drive and give it the name “RIntroDay1.R” or something similar.

Exercise 1 Solutions

Solution 1

4 * 7
## [1] 28

Solution 2

6 ^ 3
## [1] 216

Solution 3

(10-1.5) ^ (1.3 + 1.789)
## [1] 742.9765

Solution 4

(5 / 2.5) / 4
## [1] 0.5

Solution 5

obj1 <- 15

Solution 6

obj2 <- 100 + 25
obj2
## [1] 125

Solution 7

obj3 <- obj1 * obj2
obj3
## [1] 1875

Solution 8

final.answer <- (obj3-1)^ (1/4)

Solution 9

final.answer
## [1] 6.579493

Solution 10

my.text <- c('Learning R', 'is fun!')
my.text
## [1] "Learning R" "is fun!"