# t

0th

Percentile

##### Matrix Transpose

Given a matrix or data.frame x, t returns the transpose of x.

Keywords
array
##### Usage
t(x)
##### Arguments
x
a matrix or data frame, typically.
##### Details

This is a generic function for which methods can be written. The description here applies to the default and "data.frame" methods.

A data frame is first coerced to a matrix: see as.matrix. When x is a vector, it is treated as a column, i.e., the result is a 1-row matrix.

##### Value

A matrix, with dim and dimnames constructed appropriately from those of x, and other attributes except names copied across.

##### Note

The conjugate transpose of a complex matrix $A$, denoted $A^H$ or $A^*$, is computed as Conj(t(A)).

##### References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

aperm for permuting the dimensions of arrays.

• t
• t.default
• t.data.frame
##### Examples
library(base) a <- matrix(1:30, 5, 6) ta <- t(a) ##-- i.e., a[i, j] == ta[j, i] for all i,j : for(j in seq(ncol(a))) if(! all(a[, j] == ta[j, ])) stop("wrong transpose") 
Documentation reproduced from package base, version 3.3.0, License: Part of R 3.3.0

### Community examples

richie@datacamp.com at Jan 17, 2017 base v3.3.2

t() transposes the rows and columns of matrices. {r} (a_matrix <- matrix( 1:30, 5, 6, dimnames = list(rows = letters[1:5], cols = LETTERS[1:6]) )) t(a_matrix)  It also works with data frames, but the result is coerced to be a matrix. That means that every column becomes the same type! {r} data(npk) # A nitrogen, phosphate, potassium experiment npk # a data.frame with factor and numeric cols t(npk) # a character matrix  t() fails with higher dimensional arrays. You want [aperm()](https://www.rdocumentation.org/packages/base/topics/aperm) for this instead. {r} an_array <- array(1:24, 2:4) tryCatch( t(an_array), error = print )