当前位置:网站首页>dplyr 中的filter报错:Can‘t transform a data frame with duplicate names
dplyr 中的filter报错:Can‘t transform a data frame with duplicate names
2022-06-30 10:51:00 【育种数据分析之放飞自我】
背景
处理一个数据框,用filter进行筛选数据时,发现了这个报错:
aa1 %>% filter(POS_strt == “20696”)
Error infilter():
! Can’t transform a data frame with duplicate names.
Runrlang::last_error()to see where the error occurred.
根据提示运行:rlang::last_error(),也没有看到问题所在:
> rlang::last_error()
<error/rlang_error>
Error in `filter()`:
! Can't transform a data frame with duplicate names.
---
Backtrace:
1. aa1 %>% filter(POS_strt == "20696")
3. dplyr:::filter.data.frame(., POS_strt == "20696")
Run `rlang::last_trace()` to see the full context.
在网上找了很久,终于解决了,总结一下。
问题解决
主要是因为数据框中的列名有重复,其实报错中也给出了:
! Can’t transform a data frame with duplicate names.
但是,我以为是rownames有重复,其实是colnames有重复,这里检查一下:
names(aa1) %>% duplicated() %>% table

可以看到,有一个有重复。
用make.names处理一下列名,重复的后缀加.1
nn = names(aa1)
names(aa1) = make.names(nn,unique = T)
names(aa1)

可以看到,图片中的红框部分,Chrom.1名称变了,这样处理后,就不会有重复了。测试一下:

搞定!
总结
tidyverse的数据框,不能有列名重复,否者filter之类的函数都不能使用。解决方案可以用base包中的make.names处理,进行重命名。
边栏推荐
- The first China Digital Collection conference will be held soon
- DataX JSON description
- Oceanbase installation Yum source configuration error and Solutions
- Go language defer
- Flutter 从零开始 008 表单
- LVGL 8.2 re-coloring
- LVGL 8.2 Simple Colorwheel
- 启明星辰集团运维安全网关(堡垒机)再次夺得榜首!
- 20万奖金池!【阿里安全 × ICDM 2022】大规模电商图上的风险商品检测赛火热报名中!...
- Train an image classifier demo in pytorch [learning notes]
猜你喜欢

【IC5000教程】-01-使用daqIDEA图形化debug调试C代码

深潜Kotlin协程(十八):冷热数据流

MySQL导出sql脚本文件

孔松(信通院)-数字化时代云安全能力建设及趋势

记一次ViewPager + RecyclerView的内存泄漏

ESP32-C3入门教程 问题篇⑨——Core 0 panic‘ed (Load access fault). Exception was unhandled. vfprintf.c:1528

Time complexity and space complexity
![[understanding of opportunity -34]: fate is within the light cone](/img/3e/9f5630ba382df7f7ce00705445cef8.jpg)
[understanding of opportunity -34]: fate is within the light cone

焕发青春的戴尔和苹果夹击,两大老牌PC企业极速衰败

20万奖金池!【阿里安全 × ICDM 2022】大规模电商图上的风险商品检测赛火热报名中!...
随机推荐
Mathematics (fast power)
考研这些“不靠谱”的经验有多害人?
Collectors. Tomap application
在IPhone12的推理延迟仅为1.6 ms!Snap等详析Transformer结构延迟,并用NAS搜出移动设备的高效网络结构...
AMS source code analysis
The precision problem of depth texture in unity shader - stepping pit - BRP pipeline (there is no solution, it is recommended to replace URP)
【IC5000教程】-01-使用daqIDEA图形化debug调试C代码
【STL源码剖析】容器(待补充)
Go language defer
单片机 MCU 固件打包脚本软件
LVGL 8.2 menu from a drop-down list
Record the memory leak of viewpager + recyclerview once
国产自研系统的用户突破4亿,打破美国企业的垄断,谷歌后悔不迭
[leetcode 239] sliding window
Handler source code analysis
SQL必需掌握的100个重要知识点:插入数据
Dell et Apple, deux entreprises de PC établies, se sont effondrées rapidement
Use of switch statement in go language learning
SQL必需掌握的100个重要知识点:使用存储过程
【西安交通大学】考研初试复试资料分享