Chapter 33: R Data Frames

R: Data Frames.

If you’ve been following our lessons step by step, you already know:

  • vectors (lists of same-type values)
  • logical values
  • strings
  • numbers
  • how to combine strings, do math, use if-else…

Now data frames are where everything comes together — they are R’s version of Excel tables, Google Sheets, or SQL tables, but much more powerful because you can program them.

Let’s go slowly and deeply — like I’m sitting next to you in RStudio, building everything live.

1. What is a Data Frame? (The Honest Definition)

A data frame is:

  • A two-dimensional table (rows × columns)
  • Every column is a vector (and all columns must have the same number of rows)
  • Every column can have a different data type (numeric in one column, character in another, logical in another…)
  • Columns have names (like variable names)
  • Rows usually represent individual observations (people, days, transactions…)
  • Columns represent variables / features (age, name, salary, city…)

In short: Data frame = rectangular table where each column is a properly named vector of the same length.

This structure is so central that ~90% of real data analysis in R happens inside data frames.

2. How to Create a Data Frame (Manual Way – Good for Learning)

The most common way to create one from scratch:

R

Output looks like this:

text

3. Basic Things You Do with Data Frames Every Day

a) See structure & summary

R

b) Access columns (3 main ways)

R

c) Access rows

R

d) Add a new column

R

4. Filtering Rows (The Real Power)

Base R way:

R

Modern tidyverse way (much more readable):

R

5. Common Real-Life Creation Patterns (What You’ll Actually Do)

From CSV / Excel files

R

From vectors of equal length

R

6. Important Properties & Tips (2026 Style)

  • Column names should be snake_case → student_id, order_date, total_amount
  • Never use spaces or special characters in column names
  • stringsAsFactors = FALSE (or global option) — prevents automatic conversion to factors
  • tibble (from tibble package) is modern data.frame alternative — nicer printing, no partial matching
R

Your Mini Practice Right Now

R

You just created, enriched, and filtered a data frame — this is 80% of daily R work!

Feeling good?

Next logical steps?

  • Want to go deeper into dplyr verbs (filter, select, mutate, group_by, summarise)?
  • Learn joining data frames (like VLOOKUP in Excel)?
  • Or practice importing your own CSV/Excel file?

Just tell me — we continue exactly where you want! ☕📊🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *