Skip to contents

Convert Row Names to an Explicit Column

Usage

append_rownames(x, ...)

# S4 method for data.frame
append_rownames(x, after = 0, remove = TRUE, var = "rownames")

Arguments

x

A data.frame.

...

Currently not used.

after

A length-one numeric vector specifying a subscript, after which the row names are to be appended.

remove

A logical scalar: should the row names be removed?

var

A character string giving the name of column to use for row names.

Value

A data.frame.

See also

Other data preparation tools: assign(), compact(), count(), detect(), discard(), get(), keep(), seek()

Author

N. Frerebeau

Examples

X <- data.frame(
  x = 1:5,
  y = 6:10,
  z = LETTERS[1:5]
)

## Assign column to row names
(Y <- assign_rownames(X, 3))
#>   x  y
#> A 1  6
#> B 2  7
#> C 3  8
#> D 4  9
#> E 5 10

## Append row names to data.frame
(Z <- append_rownames(Y))
#>   rownames x  y
#> 1        A 1  6
#> 2        B 2  7
#> 3        C 3  8
#> 4        D 4  9
#> 5        E 5 10