The nrow()
and ncol()
functions find the number of rows and columns of a given data frame respectively.
nrow(dataframe)
ncol(dataframe)
Both the nrow()
and ncol()
functions take the same parameter value. This value represents the data frame object whose number of rows and columns is to be determined.
The nrow()
function returns the number of rows present in a given data frame, while the ncol()
function returns the number of columns present in 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)# number of rowsnrow(My_Data_Frame)# number of columnsncol(My_Data_Frame)
My_Data_Frame
, using the data.frame()
function. The data frame contains three columns.My_Data_Frame
.My_Data_Frame
, using the nrow()
function.My_Data_Frame
, using the ncol()
function.The code output tells us that the My_Data_Frame
data frame contains 3
rows and 3
columns.