R Lesson 2: Vectors and Data Frames

R Lesson 2: Vectors and Data Frames featured illustration

πŸ“Ž This article includes 1 downloadable practice file ↓

⏱ 1 min read

πŸ“˜ R Beginner Course Β· Lesson 2 of 6

Advertisement
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.

Advertisement

πŸ“Ž 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