Search notes:

R function: length

Counting the elements in a vector

If applied to a vector, length() counts its elements:
length(42:100)
# [1] 59

length("foo")
# [1] 1

length("")
# [1] 1

length(c())
# [1] 0

length(c("foo"))
# [1] 1

length(c("foo", "bar"))
# [1] 2
Github repository about-r, path: /functions/length.R

Counting columns in a data frame

If applied to a data frame, length() returns the number its columns.
In order to determine the number of observations of a data frame, nrow() can be used.

See also

Index to (some) R functions

Index