Q:

Write a R program to extract the submatrix whose rows have column value > 7 from a given matrix

0

Write a R program to extract the submatrix whose rows have column value > 7 from a given matrix.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

row_names = c("row1", "row2", "row3", "row4")
col_names = c("col1", "col2", "col3", "col4")
M = matrix(c(1:16), nrow = 4, byrow = TRUE, dimnames = list(row_names, col_names))
print("Original Matrix:")
print(M)
result = M[M[,3] > 7,]
print("New submatrix:")
print(result)

Sample Output:

[1] "Original Matrix:"
     col1 col2 col3 col4
row1    1    2    3    4
row2    5    6    7    8
row3    9   10   11   12
row4   13   14   15   16
[1] "New submatrix:"
     col1 col2 col3 col4
row3    9   10   11   12
row4   13   14   15   16

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now