5 ms·
Something I've found useful is the sqldf package [0], which lets you use data frames as tables in SQL with all the power of joins and so on. [0] https://code.g
by greenleafjacob 12y ago
Something I've found useful is the sqldf package [0], which lets you use data frames as tables in SQL with all the power of joins and so on.
[0] https://code.google.com/p/sqldf/ https://code.google.com/p/sqldf/
- hadley 12y agoNB: sqldf works by copying your data frame into a temporary SQLite database, running the query and then copying the data back. So it's not that fast. Instead, learn a native R package like dplyr or data.table that supports all the power of SQL, and is v. v. fast.
- Gatsky 12y ago+1 for dplyr. Really helpful, responsive community around it as well.
- ggrothendieck 12y ago(!) sqldf works with H2, MySQL and PostgreSQL too - its not limited to SQLite. (2) Most alternatives to SQL available in R don't work well with complex multi-way joins. You wind up materializing the full outer join first which can be quite problematic. (3) sqldf is fast enough and R is slow enough that quite often sqldf is faster than base R so if R is fast enough for you then its likely that sqldf is too. (4) The speed is often the last thing you need to worry about. The ability to express a query in a familiar way (if you know SQL) is often the more important consideration than having to learn a new system.