Programming Review

Working Environment and Programming Logic

Stat 251

2026-01-22

Last Class

  • If you made at least one submission to github, you have some points for homework #2 in Canvas

Today’s goal

  • Review function writing: section 13

  • Code chunks in quarto documents

From a block of code to functions

When you execute the same code multiple times, you should wrap the code into a function:

Code block to function

Function definitions

As an extra challenge … (for extra credit)

Can you establish how fast your function palindrome is?

Measuring speed in R

Measuring speed in python

Which is faster? R or python? - You might have to make multiple calls to the functions to capture differences

Dos and Don’ts

There are some things we should not (ever) do in R Markdown (or quarto) documents:

  • Install a package

  • Print a full data set

Next Time

  • Review for homework #3

    • indexing,
    • data frames/structures,
    • thinking in column/row-shaped objects