If you know sql, you know R

The R sqldf package allows us to execute SQL statements. The clauses, the expressions, the predicates,… are the salvation for many mediocre types such as the now-writer. sqldf is an indispensable module, even Falete’s boyfriend is able to program in SQL.

Photo by Zhang Kenny on Unsplash

Obviously I’m not going to teach you how to do queries, but I do want to show you some of the possibilities that this R package offers. “e will work with examples.


The first step is to create a data.frame:

We create a structure with two numerical variables saldo1 and saldo2, a variable client_id (autonumeric) and a factor that indicates whether the balances are alto (1) or bajo (2). The first step is to summarize the balances by the factor high. Programming in R a mediocre type as I would use the aggregate function:

It doesn’t look exactly like it should, but it’s a quick and simple code on which we can create a function and which is perfectly parameterisable. However Raul Vaquerizo, someone who believes John Locke influenced Richard Alpert more than Hume, prefers to use SQL to add data:

Simple code. Perfectly understandable by those less skilled in R. Migrating from another application to R may be less complicated than we think, we may lose the fear of a hypothetical migration. Obviously we can also make joins between tables. We compare the code in R with the analogous code in sqldf and so we learn to use the merge function:

If this union is attempted by someone who believes that the Philadelphia experiment was real, the first thing he does is a mythical left join (the maximum expression of the ineffective information manager):

The essential inner join in this monographic:

And finally the full join:


No, I didn’t forget to put the analog code in for sqldf. It’s not possible to do full join or right join in sqldf, but you won’t deny me that the code in R is very simple. Please correct me if I’m wrong and we can do full join with sqldf and I’ll modify the monographic immediately.

I hope you like it.

No matter what books or blogs or courses or videos one learns from, when it comes to implementation everything can look like “Outside the Curriculum”.

The best way to learn is by doing! The best way to learn is by teaching what you have learned!

Never give up!

See you on Linkedin!

Master in Data Science. Passionate about learning new skills. Former branch risk analyst. https://www.linkedin.com/in/oscar-rojo-martin/. www.oscarrojo.es

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store