From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

sqldf

sqldf

- [Instructor] If you know SQL you'll be pleased to know that you can use that knowledge within R dataframe. You'll use the sqldf command. Let me show you how it works. First we need some data, so we'll pull in ChickWeight, and I need to install the sqldf package. Let's run that really quick. And I bring in a library. Now I have a dataframe called ChickWeight, and let's say for instance that I would like to get the median weight of each chick and use SQL to do that research. So what I'll do is type in sqldf, which is the name of the function that I'm going to run, and then I give it SQL. So let's select the columns chick and the median of the weight column. And then I'm going to hit return just to keep things clean. And we're going to select that from a dataframe called ChickWeight, and that's from the environment right over here. There's ChickWeight that I just created. And then I'll hit return. Again, I'm just trying to keep things tidy here. Group by, let's group by Chick, again a…

Contents