rbind in R gives a weird rowname

15,329

Solution 1

Try

rownames(mydataframe) <- NULL

See the documentation (type ?rownames on the prompt) for more info.

Solution 2

You can't have duplicate rownames in a data frame or matrix. rbind() checks the rownames on the object it creates and adjusts duplicate rownames to make them unique.

You can easily reset the row names, here is a simple example:

dat1 <- data.frame(A = 1:3, B = 1:3)
dat2 <- data.frame(A = 4:6, B = 4:6)

out <- rbind(dat1[2,], dat2[2,])
rownames(out) <- NULL

Giving

> out
  A B
1 2 2
2 5 5
Share:
15,329

Related videos on Youtube

babu
Author by

babu

Updated on April 03, 2020

Comments

  • babu
    babu about 4 years

    I have the following dataframes tt1

    > tt1[2,]
            date  close emp pred
    2 1982-03-24 112.97  -1    1
    

    and dataframe tt2

    > tt2[2,]
            date  close emp pred
    2 1982-03-25 113.21   1    1
    

    when I try to use rbind() I get weird row name for the 2nd row.

    > rbind(tt1[2,],tt2[2,])
             date  close emp pred
    2  1982-03-24 112.97  -1    1
    21 1982-03-25 113.21   1    1
    

    any clue has to how to get rid of that have it as 1, 2

Related