🎓 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
Vectors are a fundamental data structure in R, used to store an ordered collection of items, typically numbers or characters. There are times when you might want to combine or concatenate two vectors to form a single one. In R, this can be easily achieved using the c() function.
2. Program Overview
This post will walk you through a simple R program that concatenates two vectors. We'll utilize R's inbuilt functions and understand each step involved.
3. Code Program
# Create two sample vectors
vector1 <- c(1, 2, 3)
vector2 <- c(4, 5, 6)
# Concatenate the vectors
concatenated_vector <- c(vector1, vector2)
# Display the concatenated vector
print(concatenated_vector)
Output:
[1] 1 2 3 4 5 6
4. Step By Step Explanation
1. We start by creating two sample vectors, vector1 and vector2, using the c() function. Here, vector1 contains the elements 1, 2, and 3, while vector2 contains the elements 4, 5, and 6.
# Create two sample vectors
vector1 <- c(1, 2, 3)
vector2 <- c(4, 5, 6)
2. To concatenate the vectors, we again use the c() function, passing in both vectors as arguments. This will combine the elements of both vectors into a single vector. The result is stored in the concatenated_vector variable.
# Concatenate the vectors
concatenated_vector <- c(vector1, vector2)
3. Finally, we use the print() function to display the concatenated_vector, which now holds the elements from both original vectors in the order they were provided.
# Display the concatenated vector
print(concatenated_vector)
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