{
  "name": "R and dplyr operations with their pandas equivalents",
  "description": "Eight common data-manipulation operations written in R (base R and dplyr) next to the equivalent pandas call in Python, compiled from the pandas documentation's R comparison quick-reference page, to show how closely the two map for everyday data wrangling.",
  "page": "https://casrai.org/guides/difference-between-python-and-r",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-12-04T09:40:00Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Operation",
      "unit": "",
      "description": ""
    },
    {
      "name": "R / dplyr",
      "unit": "",
      "description": ""
    },
    {
      "name": "pandas",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Operation": "Dimensions",
      "R / dplyr": "dim(df)",
      "pandas": "df.shape"
    },
    {
      "Operation": "First rows",
      "R / dplyr": "head(df)",
      "pandas": "df.head()"
    },
    {
      "Operation": "Filter rows",
      "R / dplyr": "filter(df, col1 == 1, col2 == 1)",
      "pandas": "df.query('col1 == 1 & col2 == 1')"
    },
    {
      "Operation": "Select columns",
      "R / dplyr": "select(df, col1, col2)",
      "pandas": "df[['col1', 'col2']]"
    },
    {
      "Operation": "Sort descending",
      "R / dplyr": "arrange(df, desc(col1))",
      "pandas": "df.sort_values('col1', ascending=False)"
    },
    {
      "Operation": "New column",
      "R / dplyr": "mutate(df, c = a - b)",
      "pandas": "df.assign(c=df['a'] - df['b'])"
    },
    {
      "Operation": "Summary statistics",
      "R / dplyr": "summary(df)",
      "pandas": "df.describe()"
    },
    {
      "Operation": "Grouped sum",
      "R / dplyr": "summarise(gdf, total = sum(col1))",
      "pandas": "df.groupby('col1').sum()"
    }
  ],
  "sources": [
    {
      "title": "pandas documentation: Comparison with R / R libraries",
      "url": "https://pandas.pydata.org/docs/getting_started/comparison/comparison_with_r.html",
      "accessed": "2026-11-14"
    }
  ]
}