Skip to content

Commit

Permalink
update new version 2025
Browse files Browse the repository at this point in the history
  • Loading branch information
fralfaro committed Jan 16, 2025
1 parent 6344c95 commit 9ef01d6
Show file tree
Hide file tree
Showing 57 changed files with 6,685 additions and 150 deletions.
162 changes: 130 additions & 32 deletions docs/examples/dplyr/dplyr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
"metadata": {},
"source": [
"<div style=\"display: flex; align-items: center;\">\n",
" <a href=\"https://github.com/fralfaro/DS-Cheat-Sheets/blob/main/docs/files/dplyr_cs.pdf\" target=\"_parent\" style=\"margin-right: 10px;\">\n",
" <img src=\"https://img.shields.io/badge/Open in PDF-%23FF0000.svg?style=flat-square&logo=adobe&logoColor=white\"/>\n",
" </a>\n",
" <a href=\"https://ds-cheat-sheets-dplyr.streamlit.app/\" target=\"_parent\" style=\"margin-right: 10px;\">\n",
" <img src=\"https://static.streamlit.io/badges/streamlit_badge_black_white.svg\"/>\n",
" </a>\n",
" <a href=\"https://colab.research.google.com/github/fralfaro/DS-Cheat-Sheets/blob/main/docs/examples/dplyr/dplyr.ipynb\" target=\"_parent\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
" </a>\n",
Expand All @@ -36,7 +30,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"library(dplyr)"
Expand All @@ -58,7 +56,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> summarize(avg = mean(mpg)) "
Expand All @@ -75,7 +77,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> count(cyl) "
Expand Down Expand Up @@ -141,7 +147,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> filter(mpg > 20)"
Expand All @@ -157,7 +167,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> distinct(gear)"
Expand All @@ -173,7 +187,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> slice(10:15)"
Expand All @@ -189,7 +207,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> slice_sample(n = 5, replace = TRUE)"
Expand All @@ -205,7 +227,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> slice_min(mpg, prop = 0.25)"
Expand All @@ -221,7 +247,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> slice_head(n = 5) "
Expand Down Expand Up @@ -257,7 +287,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> arrange(mpg)\n",
Expand All @@ -277,7 +311,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"cars |> add_row(speed = 1, dist = 1)"
Expand All @@ -301,7 +339,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> pull(wt)"
Expand All @@ -317,7 +359,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> select(mpg, wt)"
Expand All @@ -333,7 +379,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> relocate(mpg, cyl, after = last_col())"
Expand All @@ -349,7 +399,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> select(mpg:cyl)"
Expand All @@ -375,7 +429,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"df <- tibble(x_1 = c(1, 2), x_2 = c(3, 4), y = c(4, 5))"
Expand All @@ -391,7 +449,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"df |> summarize(across(everything(), mean))"
Expand All @@ -407,7 +469,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"df |> \n",
Expand All @@ -429,7 +495,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> mutate(gpm = 1 / mpg)\n",
Expand All @@ -446,7 +516,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"mtcars |> rename(miles_per_gallon = mpg)"
Expand Down Expand Up @@ -580,7 +654,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"a <- rownames_to_column(mtcars, var = \"C\")"
Expand All @@ -596,7 +674,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"column_to_rownames(a, var = \"C\")"
Expand All @@ -620,7 +702,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"x <- tribble(\n",
Expand Down Expand Up @@ -677,7 +763,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"left_join(x, y, by = join_by(A))\n",
Expand All @@ -694,7 +784,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"left_join(x, y, by = join_by(C == D))"
Expand All @@ -710,7 +804,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"left_join(x, y, by = join_by(C == D), suffix = c(\"1\", \"2\"))"
Expand Down
Loading

0 comments on commit 9ef01d6

Please sign in to comment.