R Lesson 2: Vectors and Data Frames

📎 This article includes 1 downloadable practice file ↓

⏱ 1 min read

📘 R Beginner Course · Lesson 2 of 6

“`r
qty <- c(12, 6, 2, 25) rate <- c(60, 75, 140, 35) amount <- qty * rate # whole vectors at once, like an Excel column formula df <- data.frame(item = c("Notebook", "Pens", "Stapler", "Folder"), qty, rate, amount) df[df$amount > 500, ] # rows where amount > 500
df$item # one column
str(df); summary(df)
“`

<- assigns (like =). c() combines values into a vector. Indexing starts at 1, not 0.

💡 Most R functions work on whole vectors, so you rarely need loops. Think ‘column formula’, not ‘cell by cell’.

Code for this course follows standard, current syntax; we test JavaScript and PowerShell scripts before publishing, and R/Java/Rust examples are kept to core language features. Tell us if anything fails on your setup.

Practice

Run the script line by line with Ctrl+Enter.

📎 Practice files for this article

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong