** length()** function in R Language is used to get or set the length of a vector (list) or other objects.

Syntax:length(x)

Parameters:

x:vector or object

**Example 1:**

`# R program to illustrate ` `# length function ` ` ` `# Specifing some vectors ` `x <` `-` `c(` `6` `) ` `y <` `-` `c(` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `5` `) ` ` ` `# Calling length() function ` `# to get length of the vectors ` `length(x) ` `length(y) ` |

*chevron_right*

*filter_none*

**Output :**

[1] 1 [1] 5

**Example 2:**

`# R program to illustrate ` `# length function ` ` ` `# Specifing some vectors ` `x <` `-` `c(` `3` `) ` `y <` `-` `c(` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `5` `) ` `z <` `-` `c(` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `5` `) ` ` ` `# Setting length of the vector ` `length(x) <` `-` `2` `length(y) <` `-` `7` `length(z) <` `-` `3` ` ` `# Getting elements of the ` `# new vectors ` `x ` `y ` `z ` |

*chevron_right*

*filter_none*

**Output:**

[1] 3 NA [1] 1 2 3 4 5 NA NA [1] 1 2 3

## Recommended Posts:

- Generate Color Vectors of desired Length in R Programming - rainbow() Function
- Compute the Parallel Minima and Maxima between Vectors in R Programming - pmin() and pmax() Functions
- Compute the Covariance between Two Vectors in R Programming - cov() Function
- Compute the Correlation Coefficient Value between Two Vectors in R Programming - cor() Function
- Generating sequenced Vectors in R Programming - sequence() Function
- Find positions of Matching Elements between Vectors in R Programming - match() Function
- Dot Product of Vectors in R Programming
- Cross Product of Vectors in R Programming
- Combine Vectors, Matrix or Data Frames by Columns in R Language - cbind() Function
- Combine Vectors, Matrix or Data Frames by Rows in R Language - rbind() Function
- Getting Match of an Element within a Vector in R Programming - charmatch() Function
- Getting class of different data types in R Programming - class() Function
- Getting type of different data types in R Programming - typeof() Function
- Replicating a Value to the Specified Length in R Programming - rep_len() Function
- Generate a Sequence of Length of the passed Argument in R Programming - seq_along() Function
- Search the Interval for Minimum and Maximum of the Function in R Programming - optimize() Function
- Apply a Function over a Ragged Array in R Programming - tapply() Function
- Applying a Function over an Object in R Programming - sapply() Function
- Getting Multiplication of the Objects passed as Arguments in R Language - prod() Function
- Add Leading Zeros to the Elements of a Vector in R Programming - Using paste0() and sprintf() Function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.