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.
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
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
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
4 matches
Mail list logo