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

October 12, 2021, Learn eTutorial

How to create a two-dimensional array of even integers

To create a two-dimensional array with a sequence of even integers greater than 50 using the R program, we are using array() function. This function is a built-in function of R that helps to create the array. The syntax is 

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


  • data is a vector to fill the array.
  • dim is the dim attribute for the array to be created
  • dimnames are the names for the dimensions, it can be NULL.

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

In this R program, we directly give the values to an array. Here we are using the variable Arr for holding the list elements. Here we are displaying a 5x3 integer array greater than 50, with an array length of 15(which means the number of elements in the array is 15) by 2 indicates the difference between the elements is 2. Finally, print the array.


STEP 1: Assign array elements into the variable Arr

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

STEP 3: limit the count to 15 as length.out = 15 and the difference between the numbers is 2 as by=2 for getting even numbers

STEP 4: Print the 5x3 array

R Source Code

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


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