Add Column to Data Frame in R (3 Examples) | Append Vector as New Variable to Table | cbind Function

Published: 12 March 2020
on channel: Statistics Globe
10,868
69

How to append a new variable to a data frame in the R programming language. More information: https://statisticsglobe.com/add-colum...
R syntax:


data <- data.frame(x1 = 1:5, # Create example data
x2 = letters[1:5])
vec <- c(3, 2, 3, 2, 3) # Create example vector
vec # Print example vector

##### Example 1
data_1 <- data # Replicate example data
data_1$new_col <- vec # Add new column to data

##### Example 2
data_2 <- data # Replicate example data
data_2["new_col"] <- vec # Add new column to data

##### Example 3
data_3 <- data # Replicate example data
data_3 <- cbind(data, new_col = vec) # Add new column to data


Watch video Add Column to Data Frame in R (3 Examples) | Append Vector as New Variable to Table | cbind Function online, duration hours minute second in high quality that is uploaded to the channel Statistics Globe 12 March 2020. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 10,868 times and liked it 69 visitors.