data_rotate: Rotate a data frame

View source: R/data_rotate.R

data_rotateR Documentation

Rotate a data frame

Description

This function rotates a data frame, i.e. columns become rows and vice versa. It's the equivalent of using t() but restores the data.frame class, preserves attributes and prints a warning if the data type is modified (see example).

Usage

data_rotate(data, rownames = NULL, colnames = FALSE, verbose = TRUE)

data_transpose(data, rownames = NULL, colnames = FALSE, verbose = TRUE)

Arguments

data

A data frame.

rownames

Character vector (optional). If not NULL, the data frame's rownames will be added as (first) column to the output, with rownames being the name of this column.

colnames

Logical or character vector (optional). If TRUE, the values of the first column in x will be used as column names in the rotated data frame. If a character vector, values from that column are used as column names.

verbose

Toggle warnings.

Value

A (rotated) data frame.

See Also

  • Functions to rename stuff: data_rename(), data_rename_rows(), data_addprefix(), data_addsuffix()

  • Functions to reorder or remove columns: data_reorder(), data_relocate(), data_remove()

  • Functions to reshape, pivot or rotate data frames: data_to_long(), data_to_wide(), data_rotate()

  • Functions to recode data: rescale(), reverse(), categorize(), recode_values(), slide()

  • Functions to standardize, normalize, rank-transform: center(), standardize(), normalize(), ranktransform(), winsorize()

  • Split and merge data frames: data_partition(), data_merge()

  • Functions to find or select columns: data_select(), extract_column_names()

  • Functions to filter rows: data_match(), data_filter()

Examples

x <- mtcars[1:3, 1:4]

x

data_rotate(x)
data_rotate(x, rownames = "property")

# use values in 1. column as column name
data_rotate(x, colnames = TRUE)
data_rotate(x, rownames = "property", colnames = TRUE)

# use either first column or specific column for column names
x <- data.frame(a = 1:5, b = 11:15, c = 21:25)
data_rotate(x, colnames = TRUE)
data_rotate(x, colnames = "c")


datawizard documentation built on Oct. 6, 2024, 1:08 a.m.