Create numeric vector that runs from 1 to 10 and let R print it. To create and print it right away, you need to enclose your statement with .
R solution -> dont' peek to early ;) !
(my_numeric_vector <-seq(1, 10))
# [1] 1 2 3 4 5 6 7 8 9 10
Now transform that vector so that it's 8th element is being multiplied by 4 and add 7 to it's second element. To access single elements of a vector, you need to use its index via .
R solution -> dont' peek to early ;) !
my_numeric_vector[c(8, 2)] <- c(my_numeric_vector[8] * 4,
my_numeric_vector[2] + 7)
my_numeric_vector
# [1] 1 9 3 4 5 6 7 32 9 10
Recode the continent variable into your language, or back to English. To do that, we use the function from the forcats package.
R solution -> dont' peek to early ;) !
# Recode conti to French.
# Watch out: first the new, then the old value...
conti <- fct_recode(conti,
"Europe" = "Europa",
"Afrique" = "Afrika",
"Asie" = "Asien",
"Amérique Sud" = "Suedamerika")
table(conti)
# conti
# Afrique Asie Europe S.America
# 2 1 1 1
Add Atlantis as another level. Now we need the function.
R solution -> dont' peek to early ;) !
conti <- fct_expand(conti, "Atlantis")
table(conti)
# conti
# Afrique Asie Europe S.America Atlantis
# 2 1 1 1 0
Reorder the factor vector such, that Atlantis is shown first. Now we need the function.
R solution -> dont' peek to early ;) !
conti <- fct_relevel(conti, "Atlantis")
table(conti)
# conti
# Atlantis Afrique Asie Europe S.America
# 0 2 1 1 1