Pascal triangle in matrix format

pascal(n, k = 0)

Arguments

n

natural number

k

natural number, k <= n

Details

Pascal triangle with k variations.

Value

matrix representing the Pascal triangle

See also

nchoosek

Examples

pascal(5)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    1    1    1    1
#> [2,]    1    2    3    4    5
#> [3,]    1    3    6   10   15
#> [4,]    1    4   10   20   35
#> [5,]    1    5   15   35   70
pascal(5, 1)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    0    0    0
#> [2,]    1   -1    0    0    0
#> [3,]    1   -2    1    0    0
#> [4,]    1   -3    3   -1    0
#> [5,]    1   -4    6   -4    1
pascal(5, 2)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    1    1    1    1
#> [2,]   -4   -3   -2   -1    0
#> [3,]    6    3    1    0    0
#> [4,]   -4   -1    0    0    0
#> [5,]    1    0    0    0    0