R Program to create a two-dimensional 5×3 array of sequence of even integers

How to create a two-dimensional 5×3 array of a sequence of even integers

Here we are explaining how to write an R program to create a two-dimensional 5×3 array of a sequence of even integers greater than 50. Here we are using a built-in function array() for this. This function helps to create the array. The syntax of this function is 

array(data = NA, dim = length(data), dimnames = NULL) 

Where data is a vector giving data to fill the array. The dim is the dim attribute for the array to be created and dimnames are either NULL or the names for the dimensions.

How to create a two-dimensional 5×3 array of a sequence of even integers using R program

Below are the steps used in the R program to create a two-dimensional 5×3 array of a sequence of even integers. In this R program, we directly give the values to an array. Here we are using variable for holding the list elements. Here we are displaying a 5x3 array of integers greater than 50 in length 15. Finally, print the array.

ALGORITHM

STEP 1: Assign array elements into the variable A

STEP 2: The sequence of elements are created by using seq()

STEP 3:limit the count to 15 as length.out = 15 and the numbers should be even

STEP 4: Print the 5x3 array

R Source Code

                                          A<- array(seq(from = 50, length.out = 15, by = 2), c(5, 3))
print("Content of the array is:")
print("5×3 array of sequence of even integers greater than 50:")
print(A)
                                      

OUTPUT

[1] "Content of the array is:"
[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