rbind in R gives a weird rowname

前端 未结 2 418
暗喜
暗喜 2021-01-11 13:38

I have the following dataframes tt1

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

and dataframe

相关标签:
2条回答
  • 2021-01-11 13:53

    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
    
    0 讨论(0)
  • 2021-01-11 14:07

    Try

    rownames(mydataframe) <- NULL
    

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

    0 讨论(0)
提交回复
热议问题