rownames_as_column | R Documentation |
Tools for working with row names or row ids
rownames_as_column(x, var = "rowname")
column_as_rownames(x, var = "rowname")
rowid_as_column(x, var = "rowid")
x |
A data frame. |
var |
Name of column to use for row names/ids. For |
These are similar to tibble
's functions column_to_rownames()
,
rownames_to_column()
and rowid_to_column()
. Note that the behavior of
rowid_as_column()
is different for grouped dataframe: instead of making
the rowid unique across the full dataframe, it creates rowid per group.
Therefore, there can be several rows with the same rowid if they belong to
different groups.
If you are familiar with dplyr
, this is similar to doing the following:
data |> group_by(grp) |> mutate(id = row_number()) |> ungroup()
A data frame.
# Convert between row names and column --------------------------------
test <- rownames_as_column(mtcars, var = "car")
test
head(column_as_rownames(test, var = "car"))
test_data <- head(iris)
rowid_as_column(test_data)
rowid_as_column(test_data, var = "my_id")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.