
π This article includes 1 downloadable practice file β
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
- πr-02-vectors-dataframes.RLesson code file.β¬ R Β· 221 B
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