Create a 5 by 5 matrix consisting of the numbers 1-25 and assign it to the variable mat2. The top row should be the numbers 1-5.Using indexing notation, grab a subsection of mat2 that looks like this:

1.9K    Asked by Deepabhawana in Data Science , Asked on Nov 10, 2019
Answered by Deepa bhawana

[ 7, 8]

[12,13]

Let us create a matrix of 5 by 5 consisting of numbers 1-25.

mat2 <- matrix(1:25,byrow = TRUE,nrow = 5)

mat2

image

Now to grab a subset of mat2, we can do the following.

mat2[2:3,2:3]

Output:

7 8

12 13



Your Answer

Interviews

Parent Categories