Rename duplicate records in R -


i'd rename duplicate categories in column "product" (data$product) based on order of occurrence. below data frame:

data <- data.frame(product=c("1123tr","5467yr","15-f020wm","15-f020wm","15-f020wm","15-k153cl","17-f222nr","17-f222nr"),                platform=c("caribian","flare","tease","brill","kittl","moui","mouner","fourt"),                value = c(200,500,550,456,678,765,34,33)) 

below table - how data.frame "data" looks like:

   product    platform    value    1123tr     caribian    200    5467yr     flare       500 15-f020wm     tease       550 15-f020wm     brill       456 15-f020wm     kittl       678 15-k153cl     moui        765 17-f222nr     mouner       34 17-f222nr     fourt        33 

and below desired output:

    product        platform    value     1123tr         caribian    200     5467yr         flare       500  15-f020wm(d1)     tease       550  15-f020wm(d2)     brill       456  15-f020wm(d3)     kittl       678  15-k153cl         moui        765  17-f222nr(d1)     mouner       34  17-f222nr(d2)     fourt        33 

could give me hint or advice on how please?

this close make.unique of akrun.

ave sort of thing:

> ave(as.character(data$product), data$product, fun=function(x) if (length(x)>1) paste0(x[1], '(', seq_along(x), ')') else x[1]) [1] "1123tr"       "5467yr"       "15-f020wm(1)" "15-f020wm(2)" "15-f020wm(3)" "15-k153cl"    "17-f222nr(1)" "17-f222nr(2)" 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -