0
0
R Programmingprogramming~30 mins

Adding and removing columns in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Adding and removing columns
📖 Scenario: You work in a small shop and keep track of your products in a table. Sometimes you need to add new information or remove old details from this table.
🎯 Goal: Learn how to add new columns and remove existing columns in an R data frame.
📋 What You'll Learn
Create a data frame with product names and prices
Add a new column for stock quantity
Remove the price column
Print the final data frame
💡 Why This Matters
🌍 Real World
Managing product information in a shop or business often requires updating tables by adding new details or removing outdated ones.
💼 Career
Data analysts and data scientists frequently manipulate data frames to prepare data for analysis or reporting.
Progress0 / 4 steps
1
Create the initial data frame
Create a data frame called products with two columns: name containing "Apple", "Banana", "Carrot" and price containing 1.2, 0.5, 0.3.
R Programming
Need a hint?

Use data.frame() with name = c(...) and price = c(...) to create the table.

2
Add a new column for stock quantity
Add a new column called stock to the products data frame with values 10, 20, 15.
R Programming
Need a hint?

Use products$stock <- c(10, 20, 15) to add the new column.

3
Remove the price column
Remove the price column from the products data frame using the NULL assignment.
R Programming
Need a hint?

Set products$price <- NULL to remove the column.

4
Print the final data frame
Print the products data frame to see the final table with name and stock columns.
R Programming
Need a hint?

Use print(products) to show the table.