Error in using by in R

I'm new to R and started using it to implement a gam model. I've been following this tutorial examples and R keeps throwing an error when I try to use by. I really have no idea what's wrong and would appreciate it if anybody can suggest something.