In this shot, we look at how to obtain the length of a data frame in R.
The length of a data frame is the number of columns present in the data frame.
The length()
function obtains the length of a data frame.
length(dataframe)
The length()
function takes a single and mandatory parameter that represents the data frame object whose length we have to determine.
The length()
function returns the length of a given 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))# determine the length of the data framelength(My_Data_Frame)
Line 2: We create a data frame variable, My_Data_Frame
, using the data.frame()
function. The data frame contains three columns.
Line 9: We use the length()
function to obtain the length of My_Data_Frame
.