w3resource

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.

Previous: Write a R program to create an array using four given columns,three given rows,and two given tables and display the content of the array.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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://www.w3resource.com/r-programming-exercises/array/r-programming-array-exercise-7.php