Open In App

Get Transpose of a Matrix or Data Frame in R Programming – t() Function

Last Updated : 04 Jun, 2020
Like Article

t() function in R Language is used to calculate transpose of a matrix or Data Frame.

Syntax: t(x)

x: matrix or data frame

Example 1:

# R program to illustrate
# t function
# Getting R Biochemical Oxygen Demand Dataset
# Calling t() function


  Time demand
1    1    8.3
2    2   10.3
3    3   19.0
4    4   16.0
5    5   15.6
6    7   19.8

       [, 1] [, 2] [, 3] [, 4] [, 5] [, 6]
Time    1.0  2.0    3    4  5.0  7.0
demand  8.3 10.3   19   16 15.6 19.8

Example 2:

# R program to illustrate
# t function
# Initializing a matrix with 
# 3 row and 3 columns
x <- matrix(1:9, 3, 3)
# Calling t() function


     [, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9

     [, 1] [, 2] [, 3]
[1, ]    1    2    3
[2, ]    4    5    6
[3, ]    7    8    9

Similar Reads

Convert an Object to Data Frame in R Programming - Function function in R Programming Language is used to convert an object to data frame. These objects can be Vectors, Lists, Matrices, and Factors. Syntax: Parameters: object: Vector, Matrix, factor, or data frameR - Function ExampleExample 1: Basic example of Function in R C/C++ Code # R
2 min read
Check if the Object is a Data Frame in R Programming - Function function in R Language is used to return TRUE if the specified data type is a data frame else return FALSE. R data.frame is a powerful data type, especially when processing table (.csv). It can store the data as row and columns according to the table. Syntax: Parameters: x: specified data.frame Example 1: # R progra
1 min read
Convert a Data Frame into a Numeric Matrix in R Programming - data.matrix() Function
data.matrix() function in R Language is used to create a matrix by converting all the values of a Data Frame into numeric mode and then binding them as a matrix. Syntax: data.matrix(df) Parameters: df: Data frame to be converted. Example 1: # R program to convert a data frame # into a numeric matrix # Creating a dataframe df1 = data.frame( &quot;Na
2 min read
Difference Between and data.frame() in R
R Programming Language contains a large number of data structures, data frames being very crucial in it. It is used to organize the data in a well-arranged tabular manner. Data frames can both be created from scratch as well as other data objects can be converted to data frames easily using large inbuilt R methods. The
2 min read
How to Transpose a Data Frame in R?
In this article, we will discuss how to Transpose a Data Frame in R Programming Language. we use some methods to transpose a data frame. What is Transpose?Transposing means converting rows to columns and columns to rows of a data frame. transposing can be useful for various purposes, such as reshaping data or preparing it for specific analyses. Cre
2 min read
Calculate the cross-product of the Transpose of a Matrix in R Programming - tcrossprod() Function
tcrossprod() function in R Language is used to return the cross-product of the transpose of the specified matrix. Syntax: tcrossprod(x) Parameters: x: numeric matrix Example 1: # R program to illustrate # tcrossprod function # Initializing a matrix with # 2 rows and 2 columns x &lt;- matrix(1:4, 2, 2) # Getting the matrix representation x # Calling
1 min read
Modify Data of a Data Frame with an Expression in R Programming - with() Function
with() function in R Language is used to modify data of a data frame by evaluating an expression within the arguments of the function. Syntax: with(x, expr) Parameters: x: Data frame expr: Expression to modify data Example 1: # R program to modify data of an object # Calling predefined data set BOD # Calling with() function with(BOD, {BOD$demand
1 min read
Create Matrix and Data Frame from Lists in R Programming
In R programming, there 5 basic objects. Lists are the objects that can contain heterogeneous types of elements, unlike vectors. Matrices can contain the same type of elements or homogeneous elements. On the other hand, data frames are similar to matrices but have an advantage over matrices to keep heterogeneous elements. In this article, we'll lea
3 min read
data.table vs data.frame in R Programming
data.table in R is an enhanced version of the data.frame. Due to its speed of execution and the less code to type it became popular in R. The purpose of data.table is to create tabular data same as a data frame but the syntax varies. In the below example let we can see the syntax for the data table: C/C++ Code DataTable = data.table(name = c(&quot;
3 min read
Convert a Data Frame into a Molten Form in R Programming - melt() Function
function in R Language is used to combine multiple columns of s Data Frame into a single column. Syntax: melt(x, na.rm, Parameters: x: data to be melted na.rm: Boolean value to remove NA Setting column names Example 1: # R program to reshape data frame # Loading library library(reshape) # Creating a data frame a &lt;- data.f
2 min read
Article Tags :