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

Trelliscope报错:cog_desc断言失败,x为NULL而非原子标量求助

问题解决步骤

1. 排查分组变量distinct_id的问题

报错根源是分组后出现了NULL类型的组标识,大概率是distinct_id包含NA值,或是部分分组下无有效数据。先查看变量分布:

table(pur_longdata$distinct_id, useNA = "always")
  • 若存在NA值,可直接过滤含NA的行:
    pur_longdata_clean <- pur_longdata[!is.na(pur_longdata$distinct_id), ]
    
  • 或给NA分组设置默认标识:
    pur_longdata$distinct_id[is.na(pur_longdata$distinct_id)] <- "Unknown"
    

2. 清理核心绘图变量的缺失值

Time和overall作为绘图的核心变量,它们的NA也会导致分组失效,需精准过滤:

library(dplyr)
pur_longdata_clean <- pur_longdata %>%
  filter(!is.na(Time), !is.na(overall), !is.na(distinct_id))

3. 移除空分组

确保每个distinct_id分组下至少有1条有效数据:

# 统计各分组数据量
group_counts <- pur_longdata_clean %>%
  group_by(distinct_id) %>%
  summarise(n = n())

# 移除数据量为0的分组
pur_longdata_clean <- pur_longdata_clean %>%
  filter(distinct_id %in% group_counts$distinct_id[group_counts$n > 0])

4. 重新运行绘图代码

用清理后的数据执行原代码:

library(ggplot2)
library(trelliscopejs)

qplot(Time, overall, data = pur_longdata_clean) +
  facet_trelliscope(~ distinct_id) +
  theme_bw()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 00:45:36