Re: [R] how to make row.names based on column1 with duplicated values

2018-03-01 Thread William Dunlap via R-help
You can do this with ave(): gene <- c("a","b","c","d","c","d","c","f") ave(gene, gene, FUN=function(x)if(length(x)>1)paste(x,seq_along(x),sep="-") else x) # [1] "a" "b" "c-1" "d-1" "c-2" "d-2" "c-3" "f" You can probably speed it up a bit by pulling the paste() out of FUN and doing it later.

Re: [R] how to make row.names based on column1 with duplicated values

2018-03-01 Thread PIKAL Petr
rom: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff > Newmiller > Sent: Thursday, March 1, 2018 9:13 AM > To: Stephen HonKit Wong > Cc: r-help@r-project.org > Subject: Re: [R] how to make row.names based on column1 with duplicated > values > > On Wed, 28 Feb 201

Re: [R] how to make row.names based on column1 with duplicated values

2018-03-01 Thread Jeff Newmiller
On Wed, 28 Feb 2018, Stephen HonKit Wong wrote: Dear All, Suppose I have a dataframe like this with many thousands rows all with different names: data.frame(gene=c("a","b","c","d","c","d","c","f"),value=c(20,300,48,55,9,2,100,200)), I want to set column "gene" as row.names, but there are duplic

[R] how to make row.names based on column1 with duplicated values

2018-02-28 Thread Stephen HonKit Wong
Dear All, Suppose I have a dataframe like this with many thousands rows all with different names: data.frame(gene=c("a","b","c","d","c","d","c","f"),value=c(20,300,48,55,9,2,100,200)), I want to set column "gene" as row.names, but there are duplicates (c, d), which I want to transform into this as