Skip to content

Instantly share code, notes, and snippets.

@graebnerc
Created March 31, 2022 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graebnerc/49af8ef6e17b5f66cf34443ef1d26dec to your computer and use it in GitHub Desktop.
Save graebnerc/49af8ef6e17b5f66cf34443ef1d26dec to your computer and use it in GitHub Desktop.
Solutions to the intermediate exercises of T4 of the data science course in the spring semester 2022
# T4: Intermediate exercises and possible solutions
# I. Create a vector with the numbers from -2 to 19 (step size: 0.75)
ex_1 <- seq(from=-2, to=19, by=0.75)
ex_1
# II. Create an index vector for this first vector (note: an index vector is a
# vector with all possible indices of the original vector)
ex_1_index <- seq(1, length(ex_1))
ex_1_index
# III. Compute the log of each element of the first vector using vectorisation.
# Anything that draws your attention?
ex_1_log <- log(ex_1)
ex_1_log
# IV. What happens if you concatenate vectors of different types using c()?
# Can you derive a systematization?
v_1 <- "hello"
v_2 <- c(2.3, 8)
v_3 <- c(v_1, v_2)
typeof(v_3)
v_4 <- 1L
v_5 <- c(FALSE, TRUE)
v_6 <- c(v_4, v_5)
typeof(v_6)
v_7 <- c(v_3, v_6)
typeof(v_7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment