Concatenate Elements
In R, you can concatenate elements to create a vector using the c() function. This is useful when you need to group multiple values together.
Examples of Concatenation
# Creating a numeric vector
vec <- c(1, 2, 3, 4)
Output:
[1] 1 2 3 4
# Creating a character vector
names <- c("Alice", "Bob", "Charlie")
Output:
[1] "Alice" "Bob" "Charlie"
Code Explanation: The c() function is used to combine elements into a vector. vec is a numeric vector, while names is a character vector.
Key Takeaways
- Use
c()to concatenate elements and create vectors. - Vectors can be numeric, character, or logical.