r - Note and recode duplicates -


i have dataframe that's similar what's below:

num <- c(1, 2, 3, 4) name <- c("a", "b", "c", "a") df <- cbind(num, name) 

i'm looking turn into:

num <- c(1, 2, 3, 4) name <- c("a1", "b", "c", "a2") df <- cbind(num, name) 

how automatically, since actual data larger?

i converted matrix dataframe

df <- data.frame(num, name)  #get duplicat names ext <- as.numeric(ave(as.character(df$name) , df$name,                                     fun=function(x) cumsum(duplicated(x))+1))  nms <- df$name[ext > 1]  #add data    df$newname <- ifelse( df$name %in% nms, paste0(df$name, ext), as.character(df$name)) 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -