Learn R Programming

lsr (version 1.0.0)

tFrame: Transpose a data frame

Description

Transposes a data frame, swapping rows and columns, and returns the result as a data frame.

Usage

tFrame(x)

Value

The transposed data frame.

Arguments

x

A data frame to be transposed.

Details

Equivalent to as.data.frame(t(x)). Unlike applying t directly, tFrame ensures the result is a data frame rather than a matrix. This makes sense when the rows of x can be meaningfully treated as variables — for example, when each row represents a measurement type and each column represents a participant.

See Also

Examples

Run this code
dataset <- data.frame(
  Gf = c(105, 119, 121, 98), # fluid intelligence
  Gc = c(110, 115, 119, 103), # crystallised intelligence
  Gs = c(112, 102, 108, 99) # processing speed
)
rownames(dataset) <- paste0("person", 1:4)
dataset

tFrame(dataset)

Run the code above in your browser using DataLab