R Program to Drop Columns in a Dataframe
Removes a column by assigning NULL.
name 1 Ann 2 Bob
Create, rename, extract, drop, reorder, split, merge, and list data frames. Foundational patterns for tidy data manipulation in base R.
Removes a column by assigning NULL.
name 1 Ann 2 Bob
Converts a named list into a data frame.
name age 1 Ann 19 2 Bob 21
Defines a data frame with no rows.
[1] id name <0 rows> (or 0-length row.names)
Stacks data frames with same columns using rbind.
id name 1 1 Ann 2 2 Bob 3 3 Cara
Renames a column using names().
[1] "name" "age_years"
Changes column order by indexing.
age name 1 19 Ann 2 21 Bob
Splits data frame by a grouping column.
$A group val 1 A 1 2 A 2 $B group val 3 B 3
Merges by key using merge.
id a b 1 1 10 NA 2 2 20 200 3 3 NA 300
Filters rows using a condition.
name age 2 Bob 21
Creates a list containing multiple data frames.
$df1 [1] 2 $df2 [1] 2
Concatenates strings using paste0.
[1] "Hello World"
main.R, then run Rscript main.R from your terminal. Alternatively, use an IDE such as RStudio.
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.