# Basics of R

Find the solution to these exercises without using R.

Exercise 1: Write the output.

``````4:8
``````

4 5 6 7 8

Exercise 2: Write the output.

``````3 * c(3, 4)
``````

9 12

Exercise 3: Write the output.

``````sqrt(25)
``````

5

Exercise 4: Write the output.

``````hello <- 6
Hello <- 4
hello
``````

6

Exercise 5: Solve the problem.

``````round(sum(vector)
``````

it lacks the last parenthesis `)`

Exercise 6: Solve the problem.

``````data.frame(country = c("Germany", "Argentina", "China"),
lifeexp = c(81.2, 76.2, 73.1)
``````

it lacks the last parenthesis `)`

Exercise 7: Solve the problem(s).

``````country <- c("Germany". "Argentina", "China"),
lifeexp <- c(81.2, 76.2, 73.1)
data.frame(country, lifexp)
``````

a point separates Germany and Argentina
the comma at the end of the first line should be removed in the last row, it lacks an ‘e’ in lifexp

Exercise 8: Write the output.

``````c(TRUE, 4)
``````

1 4

Exercise 9: Does this produce a character, numeric or logical vector?

``````c(TRUE, 4)
``````

numeric vector

Exercise 10: What is the output of the following code?

``````c(FALSE, "One", 2)
``````

“FALSE” “One” “2”

Exercise 11: Does this produce a character, numeric or logical vector?

``````c(FALSE, "One", 2)
``````

character vector

Exercise 12: Write the output.

``````numbers <- c(10,6,12,17,5)
numbers[3,5]
``````

12 5

Exercise 13: Write the output.

``````numbers <- c(3,22,4,23,5)
numbers[2:3]
``````

22 4

Exercise 14: Which rows and columns do we select?

``````dataframe[c(1,4), ]
``````

1st and 4th row, all columns

Exercise 15: Which rows and columns do we select?

``````dataframe[ ,"country"]
``````

All rows, the column named “country”

Exercise 16: Write the output.

``````numbers <- c(3.55, 4.99, 5.62)
round(numbers)
``````

4 5 6

Exercise 17: Write the output.

``````max(c(3.55, 4.99, 5.62))
``````

5.62

Exercise 18: Write the output.

``````max(sum(c(3.5, 6.5)))
sum(max(c(3.5, 6.5)))
``````

10 6.5

Exercise 19: Write the output.

``````as.numeric(c(FALSE, TRUE))
``````

0 1

Exercise 20: Write the output.

``````as.integer(6.2)
``````

6

Exercise 21: Write the output.

``````as.integer(factor(c("Argentina", "Zambia", "Congo")))
``````
``````end <- c(5, 9, 3)