R How to Specify Variable Names in cbind() Function (2 Examples)
This tutorial illustrates how to rename columns when using the cbind function in R.
Example 1: Using cbind without Variable Names
cbind(1:5, 2:6) # No column names # [,1] [,2] # [1,] 1 2 # [2,] 2 3 # [3,] 3 4 # [4,] 4 5 # [5,] 5 6 |
cbind(1:5, 2:6) # No column names # [,1] [,2] # [1,] 1 2 # [2,] 2 3 # [3,] 3 4 # [4,] 4 5 # [5,] 5 6
Example 2: Using cbind with Variable Names
cbind(x = 1:5, y = 2:6) # Specify column names # x y # [1,] 1 2 # [2,] 2 3 # [3,] 3 4 # [4,] 4 5 # [5,] 5 6 |
cbind(x = 1:5, y = 2:6) # Specify column names # x y # [1,] 1 2 # [2,] 2 3 # [3,] 3 4 # [4,] 4 5 # [5,] 5 6
Related Tutorials & Further Resources
Here, you may find some further resources on topics such as merging, matrices, and extracting data: