dim() function in R Language is used to get or set the dimension of the specified matrix, array or data frame.
Syntax: dim(x)
Parameters:
x: array, matrix or data frame.
Example 1:
# R program to illustrate # dim function # Getting R Biochemical Oxygen Demand Dataset BOD # Getting dimension of the above dataset dim(BOD) |
chevron_right
filter_none
Output:
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] 6 2
Example 2:
# R program to illustrate # dim function # Getting the number from 1 to 9 x <- rep(1:9) x # Calling the dim() function to # Set dimension of 3 * 3 dim(x) <- c(3, 3) # Getting the numbers # in 3 * 3 representation x |
chevron_right
filter_none
Output:
[1] 1 2 3 4 5 6 7 8 9
[, 1] [, 2] [, 3]
[1, ] 1 4 7
[2, ] 2 5 8
[3, ] 3 6 9
Recommended Posts:
- Get Transpose of a Matrix or Data Frame in R Programming - t() Function
- Get the position of the maximum element in each Row of a Matrix in R Programming - max.col() Function
- Check if the Object is a Matrix in R Programming - is.matrix() Function
- Convert a Data Frame into a Numeric Matrix in R Programming - data.matrix() Function
- Convert an Object into a Matrix in R Programming - as.matrix() Function
- Get or Set Levels of a Factor in R Programming - levels() Function
- Get or Set names of Elements of an Object in R Programming - names() Function
- Get or Set the Type of an Object in R Programming - mode() Function
- Get or Set the Structure of a Vector in R Programming - structure() Function
- Get the First parts of a Data Set in R Programming - head() Function
- Get the Last parts of a Data Set in R Programming - tail() Function
- Get the List of Arguments of a Function in R Programming - args() Function
- Transform the Scaled Matrix to its Original Form in R Programming - Using Matrix Computations
- Get Exclusive Elements between Two Objects in R Programming - setdiff() Function
- Get Indices of Specified Values of an Array in R Programming - arrayInd() Function
- Get the number of columns of an Object in R Programming - ncol() Function
- Get the number of rows of an Object in R Programming - nrow() Function
- Get the Maximum element of an Object in R Programming - max() Function
- Get the Minimum element of an Object in R Programming - min() Function
- Get Addition of the Objects passed as Arguments in R Programming - sum() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

