🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. Introduction
Adding rows to a dataframe is a common operation when working with datasets in R. This can be particularly useful when aggregating data from different sources or appending new data to an existing dataframe.
2. Program Overview
1. Create an initial dataframe.
2. Add new rows using the rbind() function.
3. Code Program
# Load necessary libraries
library(dplyr)
# Create an initial dataframe
df <- data.frame(
Name = c('Alice', 'Bob'),
Age = c(25, 30),
City = c('New York', 'Los Angeles')
)
# Print the original dataframe
print("Original Dataframe:")
print(df)
# Data for the new rows
new_rows <- data.frame(
Name = c('Charlie', 'David'),
Age = c(28, 35),
City = c('Chicago', 'San Francisco')
)
# Append new rows to the dataframe using rbind
df_updated <- rbind(df, new_rows)
# Print the updated dataframe
print("Updated Dataframe with New Rows:")
print(df_updated)
Output:
[1] "Original Dataframe:"
Name Age City
1 Alice 25 New York
2 Bob 30 Los Angeles
[1] "Updated Dataframe with New Rows:"
Name Age City
1 Alice 25 New York
2 Bob 30 Los Angeles
3 Charlie 28 Chicago
4 David 35 San Francisco
4. Step By Step Explanation
- We first create an initial dataframe df with columns Name, Age, and City.
- New rows to be added are then created in the new_rows dataframe.
- The rbind() function is used to append the rows from new_rows to df. This function combines the rows of two or more data frames.
- Note that the column names and structures of the dataframes being combined using rbind must match.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment