Home » Education » Add Index ID to Data Frame in R (3 Examples) | Create Numeric Identifier Using cbind, nrow & mutate

Add Index ID to Data Frame in R (3 Examples) | Create Numeric Identifier Using cbind, nrow & mutate

Written By Statistics Globe on Monday, Mar 08, 2021 | 10:00 AM

 
How to add a unique index ID to a data frame in the R programming language. More details: https://statisticsglobe.com/add-index-id-to-data-frame-in-r R code of this video: data <- data.frame(x1 = 15:10, # Create example data x2 = letters[1:6], x3 = 4, row.names = LETTERS[16:21]) data1 <- cbind(ID = 1:nrow(data), data) # Applying cbind function data2 <- data # Replicating data rownames(data2) <- 1:nrow(data) # Applying rownames function install.packages("dplyr") # Install & load dplyr library("dplyr") data3 <- data %>% # Applying row_number function mutate(ID = row_number()) Follow me on Social Media: Facebook: https://www.facebook.com/statisticsglobecom/ LinkedIn: https://www.linkedin.com/company/statisticsglobe/ Patreon: https://www.patreon.com/statisticsglobe Pinterest: https://www.pinterest.de/JoachimSchork Reddit: https://www.reddit.com/user/JoachimSchork Twitter: https://twitter.com/JoachimSchork