# R Data Manipulation

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

- **Type:** Skill
- **Install:** `agentstack add skill-leolin990405-r-analytics-skill-r-data-manipulation`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [LeoLin990405](https://agentstack.voostack.com/s/leolin990405)
- **Installs:** 0
- **Category:** [Data & Analytics](https://agentstack.voostack.com/c/data-and-analytics)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [LeoLin990405](https://github.com/LeoLin990405)
- **Source:** https://github.com/LeoLin990405/r-analytics-skill/tree/main/sub-skills/r-data/r-data-manipulation

## Install

```sh
agentstack add skill-leolin990405-r-analytics-skill-r-data-manipulation
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 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  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  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  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 % 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 |

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [LeoLin990405](https://github.com/LeoLin990405)
- **Source:** [LeoLin990405/r-analytics-skill](https://github.com/LeoLin990405/r-analytics-skill)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-leolin990405-r-analytics-skill-r-data-manipulation
- Seller: https://agentstack.voostack.com/s/leolin990405
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
