The dim() function checks for the dimension, i.e, the number of rows and columns present in a data frame.
dim(dataframe)
The dim() function takes a single and mandatory parameter value. This value represents the data frame object whose dimension is to be determined.
The dim() function returns the dimension of a data frame.
# creating a data frameMy_Data_Frame <- data.frame (Height = c("Tall", "Average", "short"),Body_structure = c("Meso", "Endo", "Ecto"),Age = c(35, 30, 45))# printing the data frameprint(My_Data_Frame)# dimension of the data framedim(My_Data_Frame)
My_Data_Frame, using the data.frame() function. The data frame contains three columns.My_Data_Frame data frame.My_Data_Frame data frame using the dim() function.The output of the code above,
3 3, tells us that the data frame we created is a3by3data frame. This means it contains3rows and3columns, respectively.