Guided Project - Winning Jeopardy (in R) **So much 'For Loops'**

Hey All,

Finally got through with the Jeopardy Guided Project through R and it was pretty rough considering I’m back to work. I completed the assignment + did the extra little bits outlined on the last page as well.

The issue that I’ve found is that running some of the code for the last two questions through the entire original dataset is going to take way too long based on the methods outlined in the solution. So I tried to come up with some workaround based on what I can look up. A bit faster to run but still isn’t really possible based on my codes unless I have a supercomputer to run this on.

If anyone can take a look at this and tell me what you think or how I can speed up the run time to complete the last two questions, it’ll be much appreciated.

Thanks,
Mike

Here is a link to my GitHub

1 Like

That lapply method is what isn’t taught during the DQ R pathway (but is taught using pandas with the df.apply for dataframes). Awesome job on that!

1 Like

Thanks, @manandwa. I wanted to run the entire data set, but at 10+ minutes just for a piece of code, there was no way that would work.

Someone I know mentioned using Google Labs as a workaround but haven’t really tested that out. Maybe @casey has some ideas or thoughts. IDK.

2 Likes

Hi @michael.hoang17. I was out of the office last week, please pardon the delay.

You raise good observations. I think you are on the right track with your second option where you create a function and use lapply(). I think there are still options to improve the speed of the code within R, without using a tool like Google Labs or a super computer. A good resource for ideas and essential information about functionals is the Iteration chapter in R for Data Science.

To optimize speed further, you could go deeper with vectorization and functionals (lapply(), or purrr::map()). For example, it may be worth exploring if you can build the criteria() function with vectorization/functionals insteas of the for loop. This gets a bit more advanced than we teach at Dataquest at the moment, but you’ve been exposed to the fundamental concepts in the Data Analyst in R path.

I personally like to use functionals wherever possible, but with that said, I often default back to for loops because they are less abstract.

This is a difficult subject and it takes time to learn. Thanks for posting about your experience and for sharing your code.

Best,
-Casey

1 Like