rownames_as_column {datawizard} | R Documentation |
Tools for working with row names or row ids
Description
Tools for working with row names or row ids
Usage
rownames_as_column(x, var = "rowname")
column_as_rownames(x, var = "rowname")
rowid_as_column(x, var = "rowid")
Arguments
x |
A data frame. |
var |
Name of column to use for row names/ids. For |
Details
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()
Value
A data frame.
Examples
# 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")
[Package datawizard version 0.12.2 Index]