User Write a R program to create a two-dimensional 5x3 array of sequences of even integers greater than 50
1. Introduction
This R program creates a two-dimensional 5x3 array consisting of sequences of even integers greater than 50. Each element in the array will be an even number starting from 52.
2. Program Steps
1. Generate a sequence of even integers greater than 50.
2. Create a 5x3 array using this sequence.
3. Print the resulting array.
3. Code Program
# Step 1: Generate a sequence of even integers greater than 50
even_integers <- seq(52, by = 2, length.out = 15)
# Step 2: Create a 5x3 array with the sequence
array_5x3 <- array(even_integers, dim = c(5, 3))
# Step 3: Print the array
print("5x3 Array of even integers greater than 50:")
print(array_5x3)
Output:
5x3 Array of even integers greater than 50: [,1] [,2] [,3] [1,] 52 62 72 [2,] 54 64 74 [3,] 56 66 76 [4,] 58 68 78 [5,] 60 70 80
Explanation:
1. seq(52, by = 2, length.out = 15): Generates a sequence of 15 even integers starting from 52.
2. array(even_integers, dim = c(5, 3)): Creates a 5x3 array using the sequence of even integers.
3. print("5x3 Array of even integers greater than 50:"): Prints a message indicating the array.
4. print(array_5x3): Displays the 5x3 array with the sequence of even integers.
Comments
Post a Comment