Data Frame Operations and Manipulation

Key takeaway: Practice R with 53+ runnable code examples — vectors, strings, math, data frames, recursion, and sampling — with expected output to verify instantly.

R is a programming language for statistical computing and data analysis. These examples are for data science students, researchers, analysts, and anyone learning R for coursework or work projects.

Last updated: August 2026 · 53 examples · All platforms

Quick Start

  1. Select a topic from the sidebar
  2. Study the code and expected output
  3. Run with Rscript file.R or paste into RStudio
  4. Modify inputs to experiment and learn
R Program to Change Column Name of a Dataframe
Output — Renames a column using names().
[1] "name" "age_years"
R Program to Convert a List to a Dataframe
Output — Converts a named list into a data frame.
  name age
1  Ann  19
2  Bob  21
R Program to Create an Empty Dataframe
Output — Defines a data frame with no rows.
[1] id   name
<0 rows> (or 0-length row.names)
R Program to Combine Two Dataframe into One
Output — Stacks data frames with same columns using rbind.
  id name
1  1  Ann
2  2  Bob
3  3 Cara
R Program to Drop Columns in a Dataframe
Output — Removes a column by assigning NULL.
  name
1  Ann
2  Bob
R Program to Reorder Columns in a Dataframe
Output — Changes column order by indexing.
  age name
1  19  Ann
2  21  Bob
R Program to Split Dataframe
Output — Splits data frame by a grouping column.
$A
  group val
1     A   1
2     A   2

$B
  group val
3     B   3
R Program to Merge Multiple Dataframes
Output — Merges by key using merge.
  id  a   b
1  1 10  NA
2  2 20 200
3  3 NA 300
R Program to Delete Rows From Dataframe
Output — Filters rows using a condition.
  name age
2  Bob  21
R Program to Make a List of Dataframes
Output — Creates a list containing multiple data frames.
$df1
[1] 2

$df2
[1] 2
R Program to Concatenate Two Strings
Output — Concatenates strings using paste0.
[1] "Hello World"

Frequently Asked Questions

Use Rscript from your terminal. Install R from CRAN, save as main.R, run Rscript main.R. Or use RStudio.

No, base R only. All examples use built-in functions for maximum portability.

Yes, absolutely. Copy, tweak inputs, observe outputs — experimentation is the fastest way to learn.

Yes, fully cross-platform. R runs on Windows, macOS, and Linux. Works with R 3.6+.

Learn R the Practical Way

R ranks among the top 20 languages on the TIOBE Index, dominant in academia and data science.

Topics Covered

  • Vectors, lists, and data frames
  • String manipulation and text processing
  • Math, statistics, and random sampling
  • Control flow — if/else, for, while
  • Recursion and custom functions
  • File I/O and formatted output

Who Is This For?

  • Data science students — coursework and R-based exams
  • Researchers — statistical analysis for papers
  • Analysts — data wrangling skills for work
  • Career switchers — transitioning into data roles