| data_rotate {datawizard} | R 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 |
colnames |
Logical or character vector (optional). If |
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")