Quiz
You have finished the first section: running code and assigning with <-, R's core data types, building and combining vectors, recycling and coercion, the special values, and loading packages. This short quiz checks what stuck. Pick an answer to continue; you can retry until it clicks. The last two steps are live R, run them and tinker.
What assignment does
You run score <- 90 in the console. What happens?
<- takes the value on the right and binds it to the name on the left.90 is a value, not a function body.One vector, one type
You build c(1, "two", TRUE). Because a vector holds a single type, what type does R store?
Integer or double
You type x <- 5 at the console. What does typeof(x) report?
L suffix, 5L, to get a genuine integer.Recycling the short vector
What does c(1, 2, 3, 4) * c(10, 1) return?
c(10, 1) to match the longer length, then multiplies element by element.NA is contagious
What does sum(c(2, NA, 4)) return?
na.rm = TRUE to tell sum() to drop the NA and return 6.Install once, load every time
You want to use the dplyr package in a fresh session. Which is true?
library() is per session.Vectors and their type in live R
Make a numeric vector, then ask R two things about it: what type it holds and how many elements it has. Run it, then change one number to text like "hi" and run again to watch typeof change.
typeof() tells you what a vector is made of, length() how big it is, and functions like mean() work on the whole vector at once.
Coercion in live R
A vector can hold only one type, so mixing types forces R to convert. Run this and read the result, then add TRUE to the c(...) and run again to see it become a number first.
The lone piece of text pulled the numbers up to character, so 1 is now "1". That is coercion: the most general type present wins.
Section complete
Nice work. You can assign values with <-, name R's core types and tell an integer from a double, build vectors and predict how recycling and coercion behave, reason about how NA spreads, and install and load a package. Next section: lists, data frames and tibbles, the structures that hold real datasets.