flip: Flip a Data Frame or Matrix

View source: R/flip.R

flipR Documentation

Flip a Data Frame or Matrix

Description

This function takes a data frame or matrix and flips its rows and columns, effectively transposing the data. Optionally, it can include row names in the resulting data frame.

Usage

flip(x, rownames = NULL)

Arguments

x

A data frame or matrix to be flipped.

rownames

Logical or string. If TRUE, row names will be included as the first column. If character, the column will be named respectively.

Value

A data frame with flipped rows and columns. If rownames is TRUE, row names (if x is a matrix) or the first column will contain the original row names (if x is a data frame).

See Also

t for transposing matrices and data frames.

Examples

# Create a sample data frame
df <- data.frame(Car = c("BMW", "Volvo", "Honda"), Cost = (1:3)*10000, Speed = c(140, 160, 180), Colour = c("Red", "Blue", "Brown"))

# Flip the data frame
flip(df)

flip(df) |> nice_table()

# Flip the data frame with row names included
flip(df, rownames = TRUE)


jazznbass/wmisc documentation built on Oct. 29, 2024, 5:42 p.m.