You learn more by doing

I’ve been a proponent of homework my entire teaching career. Actually sitting down and solving a problem on your own will lead you to discover intricacies in methods that a teacher cannot always fully convey. However, since I personally haven’t done homework in a while, I completely forgot about this neat little factoid. That is, until I decided to write a function in R.

Recently, I did a survey about board games on Reddit. I used Google Forms, which has different types of questions. One type of questions you can use is the “check marks” questions, where you check every option that applies out of a list. Well, Google Forms generates a CSV file for your results. In that file, a “check mark” question is treated as a single column that has all the options a person selected separated by commas, like such:

Option A, Option B, Option C
Option A, Option C
Option A, Option B, Option D, Option E
etc

In order to analyze these results, I would need each option in its own column, with the entries being 1 for that option being selected or 0 for that option not being selected. So the column above would turn into:

Option A         Option B             Option C             Option D                Option E
1                       1                           1                           0                              0
1                       0                           1                           0                              0
1                       1                           0                           1                              1

I had been thinking about how to accomplish this for a little while. From the courses on DataCamp, I knew there was a way to turn a column of single entries into several columns with zeroes and ones, and there was also a way to separate a column into multiple columns on comma separated entries. Sure, if I messed with those two options enough, I could probably figure it out after a little while. However, I decided to give it a shot writing my own function for my specific purpose. I thought about it for about a day and followed some classic advice from some very good programmers, and wrote a working prototype in about 30 minutes. It didn’t have a whole lot of options and it used nested loops (a pretty deadly sin in R) but it did what it was set out to do.

The next day, I took a dive into the ~apply family of functions in R and managed to take out both for loops in my function. I also added some extra functionality like giving the user the option to select a separator other than a comma, and whether to delete the original column.

Lately I’ve been in the process of brainstorming a bit more functionality. I am considering letting the user choose where to insert the new columns (in place of the original or at the very end of the data frame) among a couple of other options. The function could also use some improved readability and commenting. I’ll probably use it to figure out GitHub later and make a separate post about that 🙂

Writing this function taught me a few lessons that reading someone else’s code, or listening to a lecture would just never drive the point home. For example, I know very clearly understand the difference between using single or double bracket sub-setting on data frames. It’s just not something I would remember if someone told me, unless I got to experience it on my own through a simple homework assignment.

So it seems like the process is fairly simple! Come up with a process that works, no matter how inefficient, then improve efficiency and add options. I guess that applies to any solution to a problem though, doesn’t it?

Vazgen Zakaryan

“If you have to give the same advice more than three times, start a blog.”

I’ve read the quote above somewhere a couple of weeks ago, but it escapes me where. Anyway, I gave it a lot of thought because as an instructor I’ve given a lot of the same advice to a lot of my students so I figured why not, let’s write a blog.

This particular blog will focus on math education so if you hate math, feel free to stop reading 🙂  In particular, it will focus on math prerequisites.

When I taught slightly higher level mathematics courses (like Calculus II and Differential Equations), I had a decent chunk of students who were just not mathematically prepared to be in those courses and yet they somehow made it in. So after a bit of analysis, I came up with a nice hierarchy of what you should know throughout your mathematical education.

Note: This goes through Differential Equations (typically one of the last courses required for a math minor) but a similar argument may be made for higher courses as well.

Have you ever played any of those online flash games where you complete stages and level up between them? And when you level up a whooole bunch and attempt the first stage again, it’s a piece of cake? Well, math works like that too. As you take math courses, you “level up” your mathematical knowledge, and earlier topics (should) become a piece of cake. In this case, the formula is very simple: You should be very familiar with the topics of a course two “levels” below the one you are currently attending. A typical math course progression in college looks like this:
Algebra
Trigonometry
Calculus I (Differential Calculus)
Calculus II (Integral Calculus)
Calculus III (Multivariate Calculus)
Differential Equations

[Note: I did not include precalculus, as, in my experience, it’s simply college algebra with a few chapters of trigonometry thrown in. Seriously, when I taught precalculus and college algebra at the same time, the author for both books was the same. She simply took the college algebra book she wrote, didn’t even change examples, and threw in four chapters of trig right in the middle of it and called it Precalculus. Great books though.]

So if you’re attempting, say, Calculus II, you should be great at Trigonometry. Every one of these courses uses some content of the course immediately preceding it, but it really requires mastery of the course two levels before it – Calculus I is very algebra heavy especially in things like optimization problems; the most difficult problems of Calculus II usually involve some sort of trigonometry; Calculus III is just Calculus I on steroids; Differential Equations involves a lot of integrating so you have to be familiar with techniques from Calculus II. If you can keep up your mathematical mastery to where it’s two levels below where you currently are on your mathematical journey, you will be successful.

Vazgen Zakaryan