flip | R Documentation |
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.
flip(x, rownames = NULL)
x |
A data frame or matrix to be flipped. |
rownames |
Logical or string. If |
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).
t
for transposing matrices and data frames.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.