Pascal triangle


I have to write R code for creating pascal triangle. The code should such that if I enter, eg, i=400 , it should give me a pascal triangle for that.

Can anyone help me?

Pascal's Triangle

This StackOverflow thread seems like it might be a useful fit! :slightly_smiling_face:


thanks. can you also tell me, how to obtain row sum of each row in pascal triangle that is created. the sum should be 2^n.


From the stackoverflow thred @mara linked to:

pascalTriangle <- function(h) {
  lapply(0:h, function(i) choose(i, 0:i))

The run:

p = pascalTriangle(4)
unlist(lapply(p, sum))
#[1]  1  2  4  8 16

and compare with

# [1]  1  2  4  8 16


Just a friendly reminder about's homework policy: FAQ: Homework Policy

TL:DR How to Ask a Homework Related Question:

  1. Do not ask verbatim copy-paste questions
  2. Explicitly mention the course you are taking.
  3. If reasonable, be sure to ask your question as a reproducible example (reprex). Preferably using the reprex-package