Removing display of row names from data frame

后端 未结 5 1674
遥遥无期
遥遥无期 2020-11-27 16:15

I am creating a dataframe using this code:

df <- data.frame(dbGetQuery(con, paste(\'select * from test\')))

Which results in this:

5条回答
  •  遥遥无期
    2020-11-27 16:29

    Recently I had the same problem when using htmlTable() (‘htmlTable’ package) and I found a simpler solution: convert the data frame to a matrix with as.matrix():

    htmlTable(as.matrix(df))
    

    And be sure that the rownames are just indices. as.matrix() conservs the same columnames. That's it.

    UPDATE

    Following the comment of @DMR, I did't notice that htmlTable() has the parameter rnames = FALSE for cases like this. So a better answer would be:

    htmlTable(df, rnames = FALSE)
    

提交回复
热议问题