Returns the first part of an object similar to head() but subsets columns as well as rows, and also handles lists of objects.

corner(mat, n = 6)

Arguments

mat

A DataFrame, data.frame, GRanges, matrix, tibble, or list

n

Integer number of rows and columns you want returned

Value

An n x n object of the original class (or a list of n nxn objects)

Author

Emily E. Burke

Examples


m <- matrix(rnorm(1000), ncol = 10)
corner(m)
#>            [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#> [1,] -0.5101771 -0.8350650 -0.8913848  1.8146236  1.3998609  1.7227743
#> [2,]  0.9259666 -0.1581470 -0.4047318  0.1757401  1.5319521 -0.2081290
#> [3,] -0.6755356  0.3889218  0.1895938 -0.5703486 -0.1024997  0.1490822
#> [4,]  0.2068607 -0.2661767 -0.4678102 -0.5416910 -0.9556776 -0.5196651
#> [5,] -0.5352653  0.6942647 -0.8149887 -1.3265503 -1.1393273 -0.5096771
#> [6,] -0.7686770 -0.5164321 -1.3984634  1.1490047  0.5927949 -0.7821395

lis <- list(iris, mtcars, matrix(rnorm(1000), ncol = 10))
corner(lis)
#> [[1]]
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.1         3.5          1.4         0.2  setosa
#> 2          4.9         3.0          1.4         0.2  setosa
#> 3          4.7         3.2          1.3         0.2  setosa
#> 4          4.6         3.1          1.5         0.2  setosa
#> 5          5.0         3.6          1.4         0.2  setosa
#> 6          5.4         3.9          1.7         0.4  setosa
#> 
#> [[2]]
#>                    mpg cyl disp  hp drat    wt
#> Mazda RX4         21.0   6  160 110 3.90 2.620
#> Mazda RX4 Wag     21.0   6  160 110 3.90 2.875
#> Datsun 710        22.8   4  108  93 3.85 2.320
#> Hornet 4 Drive    21.4   6  258 110 3.08 3.215
#> Hornet Sportabout 18.7   8  360 175 3.15 3.440
#> Valiant           18.1   6  225 105 2.76 3.460
#> 
#> [[3]]
#>            [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#> [1,]  2.1192366 -0.1776996 -0.2756882  0.1105874  0.5455530  1.1229390
#> [2,] -0.1438535  0.7198886  1.0301346  0.4726656  1.0989664 -0.3356238
#> [3,]  1.4047266 -1.0241673  1.4780360  1.8219259  0.4179407 -0.3402345
#> [4,]  2.0100952  1.2636025  0.2400602  0.8779834  0.9713200  1.0019690
#> [5,]  2.2706804  0.5911590 -0.9280796 -0.3698947 -0.7786769  0.5136977
#> [6,] -1.1345937 -0.2842437  1.2200132  0.9360014  0.7268429 -0.5445691
#>