# How to find the length of sequence vector in R?

A sequence vector is created by using the sequence of numbers such as 1 to 15, 21 to 51, 101 to 150, -5 to 10. The length of this type of vectors can be found only by using the length function.

For example, if we have a sequence vector say X then the length of X can be found by using the command given below −

length(X)

## Example 1

To find the length of sequence vector in R, use the code given below −

x1<-c(1:51,57:200,201:213)
x1

## Output

If you execute the above given code, it generates the following output −

[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
[37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 57 58 59
[55] 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
[73] 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
[91] 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
[109] 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
[127] 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
[145] 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
[163] 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
[181] 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
[199] 204 205 206 207 208 209 210 211 212 213

To find the length of sequence vector in R, add the following code to the above code −

x1<-c(1:51,57:200,201:213)
length(x1)

## Output

If you execute all the above given codes as a single program, it generates the following output −

[1] 208

## Example 2

To find the length of sequence vector in R, use the code given below −

x2<-c(14:-50,7:48,23:98,21:-10)
x2

## Output

If you execute the above given code, it generates the following output −

[1] 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3
[19] -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21
[37] -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39
[55] -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 7 8 9 10 11 12 13
[73] 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
[91] 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 23
[109] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
[127] 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
[145] 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
[163] 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
[181] 96 97 98 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7
[199] 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10

To find the length of sequence vector in R, add the following code to the above code −

x2<-c(14:-50,7:48,23:98,21:-10)
length(x2)

## Output

If you execute all the above given codes as a single program, it generates the following output −

[1] 215

## Example 3

To find the length of sequence vector in R, use the code given below −

x3<-c(25:-100,1:78,35:-10,40:-5)
x3

## Output

If you execute the above given code, it generates the following output −

[1] 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11
[16] 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4
[31] -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19
[46] -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34
[61] -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49
[76] -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64
[91] -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79
[106] -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94
[121] -95 -96 -97 -98 -99 -100 1 2 3 4 5 6 7 8 9
[136] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
[151] 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
[166] 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
[181] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
[196] 70 71 72 73 74 75 76 77 78 35 34 33 32 31 30
[211] 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15
[226] 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
[241] -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 40 39 38 37 36
[256] 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
[271] 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6
[286] 5 4 3 2 1 0 -1 -2 -3 -4 -5

To find the length of sequence vector in R, add the following code to the above code −

x3<-c(25:-100,1:78,35:-10,40:-5)
length(x3)

## Output

If you execute all the above given codes as a single program, it generates the following output −

[1] 296

## Example 4

To find the length of sequence vector in R, use the code given below −

x4<-c(-50:25,5:61,69:151)
x4

## Output

If you execute the above given code, it generates the following output −

[1] -50 -49 -48 -47 -46 -45 -44 -43 -42 -41 -40 -39 -38 -37 -36 -35 -34 -33
[19] -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15
[37] -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3
[55] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
[73] 22 23 24 25 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[91] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
[109] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
[127] 55 56 57 58 59 60 61 69 70 71 72 73 74 75 76 77 78 79
[145] 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
[163] 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
[181] 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
[199] 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151

To find the length of sequence vector in R, add the following code to the above code −

x4<-c(-50:25,5:61,69:151)
length(x4)

## Output

If you execute all the above given codes as a single program, it generates the following output −

[1] 216

## Example 5

To find the length of sequence vector in R, use the code given below −

x5<-c(-5:100,9:79,21:-21)
x5

## Output

If you execute the above given code, it generates the following output −

[1] -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12
[19] 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[37] 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
[55] 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
[73] 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
[91] 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 9 10
[109] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
[127] 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
[145] 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
[163] 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 21 20 19
[181] 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
[199] 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17
[217] -18 -19 -20 -21

To find the length of sequence vector in R, add the following code to the above code −

x5<-c(-5:100,9:79,21:-21)
length(x5)

## Output

If you execute all the above given codes as a single program, it generates the following output −

[1] 220