Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

In R, the ** length() function** is used to get the length of the vector. In simpler terms, it is used to find out how many items are present in a vector.

```
length(x)
```

The `length`

function takes a vector object as its single parameter value.

The `length()`

function returns the length of the vector object that is passed to it in integer form.

In the code given below, we will use the `length()`

function to determine the length of a vector:

# creating a vector variable my_vector <- c(1, 2, 3, 4, 5) # using the length() function length(my_vector)

Calling the "length()" function on a vector object

- Line 2: We create a vector, using the
`c()`

function. - Line 5: We use the
`length()`

function to determine the number of items that are present in the`my_vector`

vector, which is`5`

.

RELATED TAGS

function

r

length()

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

RELATED COURSES

View all Courses

Keep Exploring

Related Courses