1. Create an integer variable e holding the value 42! Check the object class of e with class()!
Click here to see the answer
e <- 42L

class(e)
## [1] "integer"
  1. Convert e to the character data type with as.character()! Check the object class again!
Click here to see the answer
e <- as.character(e)

class(e)
## [1] "character"
  1. Create a character vector friends with four names from your circle of friends or acquaintances!
Click here to see the answer
friends <- c("Anna", "Otto", "Natan", "Ede")

friends
## [1] "Anna"  "Otto"  "Natan" "Ede"
  1. Index the second element from the vector friends!
Click here to see the answer
friends[2]
## [1] "Otto"
  1. Replace the first element of the vector friends with “Isolde” and check the updated vector again!
Click here to see the answer
freunde[1] <- "Isolde"

freunde
## [1] "Isolde" "Otto"   "Natan"  "Ede"
  1. Create a vector v1 from the following elements  1, "Hello", 2, "World" ! Check the object class!
Click here to see the answer
v1 <- c(1, "Hello", 2, "World")

v1
## [1] "1"     "Hello" "2"     "World"

class(v1)
## [1] "character"
  1. Create a vector v2 with numerical values ​​(only integers) ranging from 4 to 10!
Click here to see the answer
v2 <- c(4, 5, 6, 7, 8, 9, 10)

v2
## [1]  4  5  6  7  8  9 10

# or use the sequence operator ":"

v2 <- c(4:10)

v2
## [1]  4  5  6  7  8  9 10
  1. Index the first three elements from v2!
Click here to see the answer
v2[1:3]
## [1] 4 5 6

# or:

v2[ c(1, 2, 3) ]
## [1] 4 5 6
  1. Index all elements of v2 except the second element and save the result as v2.subset!
Click here to see the answer
v2.subset <- v2[-2]

v2.subset
## [1]  4  6  7  8  9 10
  1. Use the length () function to find out the length of v2.subset (= the number of elements in the vector)!
Click here to see the answer
length(v2.subset)
## [1] 6
  1. Calculate the arithmetic mean of vector v2! In addition, determine the standard deviation of v2.subset!
Click here to see the answer
  mean(v2)
  ## [1] 7

  sd(v2.subset)
  ## [1] 2.160247