Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dplyr <-> base R translation vignette #4755

Closed
hadley opened this issue Jan 15, 2020 · 0 comments · Fixed by #4825
Closed

dplyr <-> base R translation vignette #4755

hadley opened this issue Jan 15, 2020 · 0 comments · Fixed by #4825
Labels
documentation tidy-dev-day 🤓

Comments

@hadley
Copy link
Member

hadley commented Jan 15, 2020

One table:

  • arrange(df, x) -> df[order(x), , drop = FALSE]
  • distinct(df, x) -> df[!duplicated(x), , drop = FALSE]; unique()
  • filter(df, x) -> df[x & !is.na(x), , drop = FALSE]; subset()
  • mutate(df, z = x + y) -> df$z <- df$x + df$y; transform()
  • pull(df, x) -> df$x
  • rename(df, y = x) -> ?
  • select(df, x, y) -> df[c("x", "y")], subset()
  • select(df, starts_with("x") -> df[grepl(names(df), "^x")], etc
  • summarise(df, mean(x)) -> mean(df$x)
  • slice(df, c(1, 2, 5)) -> df[c(1, 2, 5), , drop = FALSE]

Two table:

  • inner_join(df1, df2) -> merge(df1, df2) (but mention row order)
  • left_join(df1, df2) -> merge(df1, df2, all.x = TRUE)
  • right_join(df1, df2) -> merge(df1, df2, all.y = TRUE)
  • full_join(df1, df2) -> merge(df1, df2, all = TRUE)
  • semi_join(df1, df2) -> df1[df1$x %in% df2$x, , drop = FALSE]
  • anti_join(df1, df2) -> df1[!df1$x %in% df2$x, , drop = FALSE]

Probably worth a systematic comparison only ungrouped data frames. But might be worth spelling showing a couple of special cases (e.g. ave() for grouped mutate) and then illustrating the general split(), lapply(), do.call(rbind) pattern.

@hadley hadley added documentation tidy-dev-day 🤓 labels Jan 15, 2020
@hadley hadley changed the title dplyr <-> base R translation sheet dplyr <-> base R translation vignette Jan 15, 2020
hadley pushed a commit that referenced this issue Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation tidy-dev-day 🤓
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant