[R] Fwd: rbind error - duplicated row.names not allowed

Kenn Konstabel lebatsnok at gmail.com
Tue Apr 1 12:11:22 CEST 2014


deleting the old rownames might help.

rownames(df1) <- rownames(df2) <- rownames(df3) <- NULL

But a reproducible example would be interestng. In simple cases there
is no problem with "duplicated" rownames as they are automatically
renamed:

> df1 <- data.frame(A=1, B=2, row.names="A")
> df2 <- data.frame(A=1, B=2, row.names="A")
> rbind(df1,df2)
   A B
A  1 2
A1 1 2
> df1 <- data.frame(A=1:2, B=2:3, row.names=c("A", "A1"))
> df2 <- data.frame(A=1, B=2, row.names="A")
> rbind(df1,df2)
   A B
A  1 2
A1 2 3
A2 1 2

On Mon, Mar 31, 2014 at 11:53 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
> On 01/04/14 05:42, Jefferson Ferreira Ferreira wrote:
>>
>> There are other issues here addressing the same question, but I don't
>> realize how to solve my problem based on it. So, I have 5 data frames that
>> I want to merge rows in one unique data frame using rbind, but it returns
>> the error:
>>
>> "Error in row.names<-.data.frame(*tmp*, value = value) : 'row.names'
>> duplicated not allowed In addition: Warning message: non-unique values
>> when
>> setting 'row.names': '1', '10', '100', '1000', '10000', '100000',
>> '1000000', '1000001 [....]"
>>
>> The data frames have the same columns but different number of rows. I
>> thought the rbind command took the first column as row.names. So tried to
>> put a sequential id in the five data frames but it doesn't work. I've
>> tried
>> to specify a sequential row names among the data frames via row.names()
>> but
>> with no success too. The merge command is not an option I think because
>> are
>> 5 data frames and successive merges will overwrite precedents. I've
>> created
>> a new data frame only with ids and tried to join but the resulting data
>> frame don't append the columns of joined df.
>>
>> Follows an extract of df 1:
>>
>>    id    image     power     value pol class1  1 tsx_sm_hh 0.1834515
>> -7.364787  hh    FR2  2 tsx_sm_hh 0.1834515 -7.364787  hh    FR3  3
>> tsx_sm_hh 0.1991938 -7.007242  hh    FR4  4 tsx_sm_hh 0.1991938
>> -7.007242  hh    FR5  5 tsx_sm_hh 0.2079365 -6.820693  hh    FR6  6
>> tsx_sm_hh 0.2079365 -6.820693  hh    FR[...]1802124 1802124 tsx_sm_hh
>> 0.1991938 -7.007242  hh    FR
>>
>>   The four other df's are the same structure, except the 'id' columns that
>> don't have duplicated numbers among it. 'pol' and 'image' columns are
>> defined as levels. and all.pol <- rbind(df1,df2,df3,df4,df5) return the
>> this error of row.names duplicated.
>>
>> Any idea?
>
>
> Not without a reproducible example.  If you can create one, use dput() to
> include the necessary data in your posting.
>
> You *might* try something like:
>
>         e1 <- df1[1:5,1:2]
>         e2 <- df2[1:5,1:2]
>         ee <- rbind(e1,e2)
>
> If that throws the error, include dput(e1) and dput(e2) in your posting. If
> it *doesn't* then this might give you some insight into just what is
> triggering the error.
>
> Look at rownames(df1) and rownames(df2) as well as rownames(e1) and
> rownames(e2).
>
> cheers,
>
> Rolf Turner
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list