Skip to content
Back to skills

Tm

ASecurity

R tm package for text mining. Use for classic text mining infrastructure and preprocessing.

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

Security analysis

A100/100

Scanned June 4, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Tm?

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

Security grade badge for Tm
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-tm/badge)](https://www.skillsdirectory.com/skills/leolin990405-tm)

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: tm
description: R tm package for text mining. Use for classic text mining infrastructure and preprocessing.
---

# tm Package

Text mining infrastructure.

## Corpus

```r
library(tm)

# From vector
corp <- VCorpus(VectorSource(texts))

# From directory
corp <- VCorpus(DirSource("texts/"))

# From data frame
corp <- VCorpus(DataframeSource(df))
```

## Preprocessing

```r
# Transform functions
corp <- tm_map(corp, content_transformer(tolower))
corp <- tm_map(corp, removePunctuation)
corp <- tm_map(corp, removeNumbers)
corp <- tm_map(corp, removeWords, stopwords("english"))
corp <- tm_map(corp, stripWhitespace)
corp <- tm_map(corp, stemDocument)

# Custom function
corp <- tm_map(corp, content_transformer(function(x) gsub("pattern", "", x)))
```

## Document-Term Matrix

```r
# Create DTM
dtm <- DocumentTermMatrix(corp)

# Term-Document Matrix
tdm <- TermDocumentMatrix(corp)

# With controls
dtm <- DocumentTermMatrix(corp,
  control = list(
    weighting = weightTfIdf,
    minWordLength = 3,
    bounds = list(global = c(5, Inf))
  )
)
```

## Inspection

```r
# Inspect
inspect(dtm[1:5, 1:10])

# Find frequent terms
findFreqTerms(dtm, lowfreq = 100)

# Find associations
findAssocs(dtm, "data", corlimit = 0.5)
```

## Sparse Matrix

```r
# Remove sparse terms
dtm <- removeSparseTerms(dtm, sparse = 0.95)

# Convert to matrix
m <- as.matrix(dtm)

# To data frame
df <- as.data.frame(as.matrix(dtm))
```

## Dictionary

```r
dict <- c("good", "bad", "excellent")
dtm_dict <- DocumentTermMatrix(corp,
  control = list(dictionary = dict)
)
```

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.