R Programming: Create a vector using : operator and seq() function
R Programming: Vector Exercise-28 with Solution
Write a R program to create a vector using : operator and seq() function.
Sample Solution :
R Programming Code :
x = 1:15
print("New vector using : operator-")
print(x)
print("New vector using seq() function-")
print("Specify step size:")
y = seq(1, 3, by=0.3)
print(y)
print("Specify length of the vector:")
z = seq(1, 5, length.out = 6)
print(z)
Sample Output:
[1] "New vector using : operator-" [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [1] "New vector using seq() function-" [1] "Specify step size:" [1] 1.0 1.3 1.6 1.9 2.2 2.5 2.8 [1] "Specify length of the vector:" [1] 1.0 1.8 2.6 3.4 4.2 5.0
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to add 3 to each element in a given vector. Print the original and new vector.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics