Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

variables-types-r

Variables and types

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Variables and types: the syntax, patterns, and safety habits you need before advancing in R.

Teams still ship Variables and types in R codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Variables and types in contexts like: Research pipelines, Shiny dashboards, and statistical reporting.

Write R in the editor and click Run on server—the dev runner executes with Rscript; use print() or cat() and base R in playground snippets (tidyverse locally; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

R variables are bindings in an environment—assignment uses <- (preferred) or =. Types are attached to objects; vectors are homogeneous (one type per vector), unlike mixed Python lists.

Common atomic types

  • numeric — doubles by default (integers exist but are less common)
  • character — text strings
  • logicalTRUE, FALSE, NA
  • integer — suffix L, e.g. 5L

Assignment and class()

count <- 10
ratio <- 0.75
name <- "Ada"
ok <- TRUE
print(class(count))
print(typeof(name))

Use class() and typeof() to inspect objects—compare with type() in Python.

Important interview questions and answers

  1. Q: Why <- over =?
    A: Both assign; <- is idiomatic and avoids confusion with function arguments using =.
  2. Q: Are R vectors homogeneous?
    A: Yes—c(1, "a") coerces to character; use lists for mixed types.

Self-check

  1. What does class(3.14) return?
  2. Can one vector hold numbers and strings without coercion?

Pitfall: Vectors are homogeneous—c(1, "a") coerces to character; use lists for mixed types.

Interview prep

<- vs =?

<- is idiomatic for assignment; = works but can confuse with named arguments.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • <- vs =?
  • class() vs typeof()?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump