Skip to contents

Return a corner of a matrix or data frame (i.e., upper left, upper right, lower left, lower right).

Usage

corner(x, corner = 1, size = 5)

Arguments

x

Data frame or matrix.

corner

Integer in the set 1, 2, 3, 4 or character in the set 'topleft', 'topright', 'bottomleft', 'bottomright' or in the set 'tl', 'tr', 'bl', 'br'. Indicates which corner to return. Integers 1, 2, 3 and 4 correspond to top left, top right, bottom left, and bottom right corners. The default is 1, the top left corner.

size

Positive integer, number of rows and columns to return. If there are fewer columns/rows than indicated then all columns/rows are returned.

Value

A matrix or data.frame.

See also

Examples

x <- matrix(1:120, ncol=12, nrow=10)
x
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#>  [1,]    1   11   21   31   41   51   61   71   81    91   101   111
#>  [2,]    2   12   22   32   42   52   62   72   82    92   102   112
#>  [3,]    3   13   23   33   43   53   63   73   83    93   103   113
#>  [4,]    4   14   24   34   44   54   64   74   84    94   104   114
#>  [5,]    5   15   25   35   45   55   65   75   85    95   105   115
#>  [6,]    6   16   26   36   46   56   66   76   86    96   106   116
#>  [7,]    7   17   27   37   47   57   67   77   87    97   107   117
#>  [8,]    8   18   28   38   48   58   68   78   88    98   108   118
#>  [9,]    9   19   29   39   49   59   69   79   89    99   109   119
#> [10,]   10   20   30   40   50   60   70   80   90   100   110   120
corner(x, 1)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1   11   21   31   41
#> [2,]    2   12   22   32   42
#> [3,]    3   13   23   33   43
#> [4,]    4   14   24   34   44
#> [5,]    5   15   25   35   45
corner(x, 2)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]   71   81   91  101  111
#> [2,]   72   82   92  102  112
#> [3,]   73   83   93  103  113
#> [4,]   74   84   94  104  114
#> [5,]   75   85   95  105  115
corner(x, 3)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    6   16   26   36   46
#> [2,]    7   17   27   37   47
#> [3,]    8   18   28   38   48
#> [4,]    9   19   29   39   49
#> [5,]   10   20   30   40   50
corner(x, 4)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]   76   86   96  106  116
#> [2,]   77   87   97  107  117
#> [3,]   78   88   98  108  118
#> [4,]   79   89   99  109  119
#> [5,]   80   90  100  110  120