Data Frame Operations and Manipulation

Create, rename, extract, drop, reorder, split, merge, and list data frames. Foundational patterns for tidy data manipulation in base R.

R Program to Make a List of Dataframes

Program (R)
Example & Expected Output

Creates a list containing multiple data frames.

$df1
[1] 2

$df2
[1] 2

R Program to Convert a List to a Dataframe

Program (R)
Example & Expected Output

Converts a named list into a data frame.

  name age
1  Ann  19
2  Bob  21

R Program to Create an Empty Dataframe

Program (R)
Example & Expected 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

Program (R)
Example & Expected Output

Stacks data frames with same columns using rbind.

  id name
1  1  Ann
2  2  Bob
3  3 Cara

R Program to Change Column Name of a Dataframe

Program (R)
Example & Expected Output

Renames a column using names().

[1] "name" "age_years"

R Program to Drop Columns in a Dataframe

Program (R)
Example & Expected Output

Removes a column by assigning NULL.

  name
1  Ann
2  Bob

R Program to Reorder Columns in a Dataframe

Program (R)
Example & Expected Output

Changes column order by indexing.

  age name
1  19  Ann
2  21  Bob

R Program to Split Dataframe

Program (R)
Example & Expected 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

Program (R)
Example & Expected 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

Program (R)
Example & Expected Output

Filters rows using a condition.

  name age
2  Bob  21

R Program to Concatenate Two Strings

Program (R)
Example & Expected Output

Concatenates strings using paste0.

[1] "Hello World"

Frequently Asked Questions

Install R (from CRAN). Save the code in a file like main.R, then run Rscript main.R from your terminal. Alternatively, use an IDE such as RStudio.

No. All examples rely on base R functions to ensure compatibility across systems. Where packages are useful, they’ll be explicitly mentioned.

Yes. Copy the code, tweak inputs, and observe outputs. Experimentation is the fastest way to build intuition and mastery.

Yes. R is cross-platform. The examples run on Windows, macOS, and Linux with a standard R installation.

Learn R the Practical Way

R is a powerful language for data analysis, visualization, and statistical computing. Practicing small, focused programs builds fluency with vectors, data frames, lists, functions, control flow, and string manipulation.

On this page, you’ll find clean, well-formatted examples that run across platforms. Each example includes a short description and expected output so you can quickly verify your understanding. Explore the topics via the sidebar and extend the code to experiment further.

Whether you’re preparing for coursework, handling data tasks at work, or learning R for research, these examples offer a practical path to mastery. Bookmark the page and revisit to keep sharpening your skills.