Skip to content
Back to skills

R Data Manipulation

ASecurity

R data manipulation with dplyr, data.table, tidyr. Use for filtering, selecting, mutating, grouping, summarizing, reshaping data frames.

  • 5 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added June 4, 2026
datagoapiperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill r-data-manipulation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Data Manipulation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Data Manipulation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r-data-manipulation/badge)](https://www.skillsdirectory.com/skills/leolin990405-r-data-manipulation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: r-data-manipulation
description: R data manipulation with dplyr, data.table, tidyr. Use for filtering, selecting, mutating, grouping, summarizing, reshaping data frames.
---

# R Data Manipulation

Data frame manipulation with dplyr, data.table, and tidyr.

## dplyr (Tidyverse)

```r
library(dplyr)

# Core verbs
df %>%
  filter(x > 10, y == "A") %>%      # Filter rows
  select(a, b, c) %>%               # Select columns
  mutate(d = a + b) %>%             # Create/modify columns
  arrange(desc(a)) %>%              # Sort rows
  group_by(category) %>%            # Group

  summarise(                        # Aggregate
    mean = mean(value),
    sd = sd(value),
    n = n()
  ) %>%
  ungroup()

# Joins
left_join(df1, df2, by = "id")
inner_join(df1, df2, by = c("a" = "b"))
anti_join(df1, df2, by = "id")

# Window functions
df %>%
  group_by(category) %>%
  mutate(
    rank = row_number(),
    cumsum = cumsum(value),
    lag_val = lag(value, 1),
    lead_val = lead(value, 1)
  )

# Conditional
df %>% mutate(
  category = case_when(
    x < 10 ~ "low",
    x < 50 ~ "medium",
    TRUE ~ "high"
  ),
  y = if_else(x > 0, log(x), NA_real_)
)

# across() for multiple columns
df %>%
  mutate(across(where(is.numeric), scale)) %>%
  summarise(across(c(a, b), list(mean = mean, sd = sd)))
```

## data.table (High Performance)

```r
library(data.table)
dt <- as.data.table(df)

# Basic syntax: dt[i, j, by]
dt[x > 10]                          # Filter (i)
dt[, .(a, b)]                       # Select (j)
dt[, sum(value)]                    # Aggregate
dt[, .(total = sum(value)), by = category]  # Group by

# Modify in place
dt[, new_col := a + b]              # Add column
dt[, c("a", "b") := NULL]           # Remove columns
dt[x < 0, x := 0]                   # Conditional update

# Chaining
dt[x > 10][order(-value)][, head(.SD, 5), by = category]

# Keys and joins
setkey(dt1, id)
setkey(dt2, id)
dt1[dt2]                            # Join

# .SD (Subset of Data)
dt[, lapply(.SD, mean), by = category, .SDcols = c("a", "b")]

# fread/fwrite (fast I/O)
dt <- fread("data.csv")
fwrite(dt, "output.csv")
```

## tidyr (Reshaping)

```r
library(tidyr)

# Pivot longer (wide to long)
df %>% pivot_longer(
  cols = c(col1, col2, col3),
  names_to = "variable",
  values_to = "value"
)

# Pivot wider (long to wide)
df %>% pivot_wider(
  names_from = variable,
  values_from = value
)

# Separate and unite
df %>% separate(col, into = c("a", "b"), sep = "-")
df %>% unite("combined", a, b, sep = "_")

# Nested data
df %>% nest(data = -group)
df %>% unnest(data)

# Missing values
df %>% drop_na()
df %>% fill(column, .direction = "down")
df %>% replace_na(list(x = 0, y = "unknown"))
```

## Comparison

| Operation | dplyr | data.table |
|-----------|-------|------------|
| Filter | `filter(x > 10)` | `dt[x > 10]` |
| Select | `select(a, b)` | `dt[, .(a, b)]` |
| Mutate | `mutate(c = a+b)` | `dt[, c := a+b]` |
| Group + Summarise | `group_by() %>% summarise()` | `dt[, .(), by=]` |
| Speed | Good | Fastest |
| Memory | Copies | In-place |

Files in this skill

  • DataExplorer/SKILL.md2.6 KB
  • SKILL.md3 KB
  • broom/SKILL.md3 KB
  • data.table/SKILL.md2.6 KB
  • dplyr/SKILL.md2.8 KB
  • fuzzyjoin/SKILL.md2.5 KB
  • janitor/SKILL.md2.9 KB
  • lubridate/SKILL.md1.8 KB
  • purrr/SKILL.md2.8 KB
  • reshape2/SKILL.md1.9 KB
  • stringi/SKILL.md2.5 KB
  • stringr/SKILL.md2.3 KB
  • tidyr/SKILL.md2.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.