The “cbind” Function in R
Package: Base R (no specific package required)
Purpose: Combines vectors, matrices, or data frames by column.
General Class: Data Manipulation
Required Argument(s):
Vectors, matrices, or data frames to be combined by column.
Notable Optional Arguments:
None
Example:
# Example data for using the cbind function
names <- c("Alice", "Bob", "Charlie")
ages <- c(25, 30, 22)
# Combine two vectors into a matrix by column
combined_matrix <- cbind(Names = names, Ages = ages)
# Display the result
print(combined_matrix)In this example, the cbind function is used to combine two vectors (names and ages) into a matrix (combined_matrix) by column. The resulting matrix has two columns, one for names and one for ages. The cbind function is commonly used for combining data in a column-wise fashion, especially when working with data frames or matrices.