You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从R语言数据框列中提取表情符号并统计使用频次?

提取并统计数据集中的表情符号频次

你可以借助tidyverse工具包完成这个需求,具体步骤如下:

  1. 先加载所需的工具包:
library(tidyverse)
  1. 处理数据集,提取表情符号并统计频次:
# 你的原始数据集
df <- tribble(
  ~sentence, 
  "Ask yourself: 😅 “Does this person fully understand all of their responsibilities?🎉",
  "What do you see as the reason for it? 🎉",
  "Your goal 🚀is to get perspective on the situation. ✅"
)

# 核心处理代码
emoji_stats <- df %>%
  # 提取每行中的所有表情符号,返回列表
  mutate(emojis = str_extract_all(sentence, "[\\p{Emoji}]")) %>%
  # 将列表展开为每行一个表情符号
  unnest(emojis) %>%
  # 统计每个表情的出现次数,并重命名频次列为used
  count(emojis, name = "used")

# 输出结果
emoji_stats

运行上述代码后,emoji_stats就是你需要的结果,结构和示例一致:

# A tibble: 4 × 2
  emojis  used
  <chr>  <int>
1 😅         1
2 🎉         2
3 🚀         1
4 ✅         1

关键说明

  • str_extract_all(sentence, "[\\p{Emoji}]"):利用Unicode正则表达式匹配所有表情符号,能覆盖绝大多数常见表情。
  • unnest(emojis):把每行的表情符号列表拆分成独立行,方便后续统计。
  • count(emojis, name = "used"):自动统计每个表情的出现次数,并重命名频次列。

内容的提问来源于stack exchange,提问作者datazang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 06:10:28