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

R语言非唯一值场景下数据框列提取报错排查与解决

问题解决:从DataFrame提取符合条件的列及其相邻列

需求目标

从一个DataFrame中提取符合另一个DataFrame条件的某列,以及该列右侧相邻的列。

初始实现方案

使用匿名函数遍历每行,通过match参数匹配dfa$result的值,选择df23中对应的列(致谢@jay.sf)。

问题现象

当dfa$result存在非唯一值(如Noradrenaline.stop.time.variation重复出现)时,会触发报错:

Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 1, 0

解决方法

借助tidyverse工具链完成处理:

  • 使用pivot_longer将宽表df23转换为长表格式
  • 通过right_join关联dfa,匹配对应数据
  • 重命名匹配后的目标列,最终合并得到结果

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 18:27:18