Skip to contents

Assign a Specific Row/Column to the Column/Row Names

Usage

assign_colnames(x, ...)

assign_rownames(x, ...)

# S4 method for class 'data.frame'
assign_rownames(x, column, remove = TRUE)

# S4 method for class 'data.frame'
assign_colnames(x, row, remove = TRUE)

Arguments

x

A data.frame.

...

Currently not used.

column

A length-one numeric vector specifying the column number that is to become the row names.

remove

A logical scalar: should the specified row/column be removed after making it the column/row names?

row

A length-one numeric vector specifying the row number that is to become the column names.

Value

A data.frame.

See also

Other data preparation tools: append_column(), append_rownames(), 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