length()
get_help()
docs
The length()
function comes with R
and is part of the Base R
{base}
package.
We use this function to determine the length of a value or variable, most commonly of array or list. Note that this function WILL NOT tell you the length of a string (i.e., how many characters it contains); instead, use nchar()
to ask how long a string is.
length(array to find the length of)
# Find the length of an array directly
length( c(44, 55, 66) )
## [1] 3
# Find the length of an array which has been defined as a variable
<- c(44, 55, 66)
my_array length(my_array)
## [1] 3
## CAUTION! length() does not work properly to find the number of characters in a string
length("R thinks this string is a single value in an array of length 1")
## [1] 1