function similar to head() for matrix

1.8k views Asked by At

I am looking for a function in any package that can print matrix[1:5, 1:5]. head() is good for those that have few columns but not for a large matrix. I know I can create my own function for it but I am wondering if there is a function for it already.

1

There are 1 answers

0
Maiasaura On BEST ANSWER

There is a function called peek in a package called futile.matrix.

library(futile.matrix)
m <- matrix(c(1,3,4,2, 5,10,11,2, 3,42,8,22, 23,15,3,8), ncol = 4)
peek(m, 4)

From the description of that function:

"Peek is a simple utility to conveniently look at a portion of a matrix. This is similar to head and tail but provides a 2-dimensional slice instead of a complete row."