Create a 5×3 Array of Sequence of Even Integers greater than 50 in R
R Programming: Array Exercise-7 with Solution
Write a R program to create a two-dimensional 5×3 array of sequence of even integers greater than 50.
Sample Solution :
R Programming Code :
# Create a sequence of 15 even integers starting from 50, incrementing by 2, and reshape it into a 5x3 array
a <- array(seq(from = 50, length.out = 15, by = 2), c(5, 3))
# Print a label indicating the content of the array
print("Content of the array:")
# Print a description of the array's content
print("5×3 array of sequence of even integers greater than 50:")
# Print the actual 5x3 array
print(a)
Output:
[1] "Content of the array:" [1] "5×3 array of sequence of even integers greater than 50:" [,1] [,2] [,3] [1,] 50 60 70 [2,] 52 62 72 [3,] 54 64 74 [4,] 56 66 76 [5,] 58 68 78
Explanation:
- a <- array(seq(from = 50, length.out = 15, by = 2), c(5, 3))
- Generate Sequence: seq(from = 50, length.out = 15, by = 2) creates a sequence of 15 even integers starting from 50 (i.e., 50, 52, 54, ..., 78).
- Create Array: array(..., c(5, 3)) reshapes this sequence into a 5×3 two-dimensional array.
- print("Content of the array:")
- Prints a Label: Outputs the text "Content of the array:" to indicate that the following output will be the array content.
- print("5×3 array of sequence of even integers greater than 50:")
- Prints a Description: Outputs the text "5×3 array of sequence of even integers greater than 50:" to describe the array's content.
- print(a)
- Prints the Array: Outputs the 5×3 array created in the previous step.
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/r-programming-exercises/array/r-programming-array-exercise-7.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics