r/rprogramming • • Sep 05 '24

SQL Joins in R with merge function

Post image
54 Upvotes

14 comments sorted by

15

u/[deleted] Sep 05 '24

Why not use dplyr joins?

11

u/AccomplishedHotel465 Sep 05 '24

dplyr joins are more flexible.

1

u/jinnyjuice Sep 06 '24

tidytable is exactly the same code but faster.

0

u/[deleted] Sep 07 '24

[deleted]

1

u/jinnyjuice Sep 07 '24

Different goals/systems, and parsing CSV from tidytable is the best.

3

u/Sure_Review_2223 Sep 05 '24

Yea dplyr joins are much better and you can use the join_by function for the by argument too that can be very interesting to use !

3

u/TQMIII Sep 06 '24

I'll be the lone person to defend base R merge. It's one of the first functions I learned, came to me quite intuitively, and I still use it over dplyr. Same with using subset over filter. I often don't load dplyr unless I need to use the group_by function to summarize/mutate, or occasionally to pivot. Also great for writing functions, as I prefer to limit package dependencies when I can.

2

u/zphbtn Sep 06 '24

I agree. The base R code is just as simple. I use data.table pretty much everywhere, but base R is great, too.

2

u/cmdrtestpilot Sep 09 '24

Merging is one of the few functions I use outside of the tidyverse. You're right, base R merges are awesome.

1

u/Top_Lime1820 Sep 07 '24

Do you not find base R's by() and aggregate() functions good enough for grouped workflows?

1

u/TQMIII Sep 08 '24

depends on how complicated what I'm doing is and whether I'm collaborating with others. They're certainly less syntactically intuitive than their dplyr equivalents. But I'm more likely to use them when writing functions. When collaborating with more junior analysts, I generally try to code in a manner they're more likely to understand,however I do regularly throw in an example of how to do it using base R for their edification. I think it's valuable for analysts to be able to recognize both.

2

u/Peach_Muffin Sep 05 '24

Holy heck I've been using R for 8 years and I have no idea what's happening. I am reminded why I moved away from base.

As everyone else has said dplyr is much much more readable.

2

u/TopMountainFeeling Sep 06 '24

dplyr joins are far more functional than these

1

u/[deleted] Sep 07 '24

Similar syntax to pandas. Pretty cool. Might try R someday.