The dim() function is used to get dimension of data frame, matrix or array in R.
The following method shows how you can do it with syntax.
Method: Use dim() Function
dim(dataframe)
The following example shows how you can use the dim() function in R.
Use dim() Function to Get Dimension of Data Frame
Let’s apply dim() function on data frame:
# Create data frame
df <- data.frame(Machine_name=c("A","B","C","D","E","F"),
Pressure=c(78.2, 71.7, 80.21, 83.12, 82.56, 79.50),
Temperature=c(31, 35, 36, 36, 38, 32),
Status=c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE))
# Calculate diamension
d <- dim(df)
# Print diamension
print(d)
Output:
[1] 6 4
The output shows total number of rows and column of data frame.