Check your understanding

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.

Question 1 of 8

What assignment does

You run score <- 90 in the console. What happens?

Right. <- takes the value on the right and binds it to the name on the left.
90 is a value, not a function body.
Question 2 of 8

One vector, one type

You build c(1, "two", TRUE). Because a vector holds a single type, what type does R store?

Correct. Coercion follows logical to integer to double to character, and the highest type present wins.
An atomic vector cannot be mixed; that is what lists are for.
Question 3 of 8

Integer or double

You type x <- 5 at the console. What does typeof(x) report?

Right. Add the L suffix, 5L, to get a genuine integer.
Typing a number gives a number, not text.
Question 4 of 8

Recycling the short vector

What does c(1, 2, 3, 4) * c(10, 1) return?

Correct. R repeats c(10, 1) to match the longer length, then multiplies element by element.
The operator is multiplication, and the result keeps the longer length.
Question 5 of 8

NA is contagious

What does sum(c(2, NA, 4)) return?

Right. Add na.rm = TRUE to tell sum() to drop the NA and return 6.
It is a valid value; it just propagates through the arithmetic.
Question 6 of 8

Install once, load every time

You want to use the dplyr package in a fresh session. Which is true?

Correct. Installation is one-time; loading with library() is per session.
Base R loads automatically, but add-on packages must be installed and loaded.
Run it: build a vector

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.

RInteractive R
days <- c(3, 8, 1, 12, 5) typeof(days) length(days) mean(days)

  

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.

Run it: watch coercion

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.

RInteractive R
mixed <- c(1, 2, "three") mixed typeof(mixed)

  

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.