当前位置:网站首页>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处理,进行重命名。
边栏推荐
- Dickinson's soul chooses its companion
- The first China Digital Collection conference will be held soon
- 100 important knowledge points that SQL must master: using stored procedures
- 14岁懂社会-《关于“工作的幸福”这件事儿》读书笔记
- 数据库什么时候需要使用索引【杭州多测师】【杭州多测师_王sir】
- 创建型-配置工厂
- 微信表情符号被写入判决书,你发的每个 emoji 都可能成为呈堂证供
- [untitled]
- When does the database need to use the index [Hangzhou multi surveyors] [Hangzhou multi surveyors _ Wang Sir]
- Iptables target tproxy
猜你喜欢

The two e-commerce bigwigs' lacy news screens represent the return of e-commerce to normal, which will be beneficial to the real economy

中移OneOS开发板学习入门

煥發青春的戴爾和蘋果夾擊,兩大老牌PC企業極速衰敗

Jetpack Compose DropdownMenu跟随手指点击位置显示

China will force a unified charging interface. If Apple does not bow its head, iPhone will be kicked out of the Chinese market
![[机缘参悟-34]:光锥之内皆命运](/img/3e/9f5630ba382df7f7ce00705445cef8.jpg)
[机缘参悟-34]:光锥之内皆命运

The precision problem of depth texture in unity shader - stepping pit - BRP pipeline (there is no solution, it is recommended to replace URP)

启明星辰集团运维安全网关(堡垒机)再次夺得榜首!

记一次ViewPager + RecyclerView的内存泄漏

Oceanbase installation Yum source configuration error and Solutions
随机推荐
林克庆到番禺区调研“发展要安全”工作 以“时时放心不下”责任感抓好安全发展各项工作
It's time for the kotlin coroutine to schedule thread switching to solve the mystery
Time complexity and space complexity
10 reasons for system performance failure
100 important knowledge points that SQL must master: summary data
[STL source code analysis] iterator
SQL必需掌握的100个重要知识点:插入数据
ESP32-C3入门教程 基础篇⑪——Non-Volatile Storage (NVS) 非易失性存储参数的读写
Ant financial's written test question: what can be quantified in the requirements document? [Hangzhou multi tester] [Hangzhou multi tester \wang Sir]
【IC5000教程】-01-使用daqIDEA图形化debug调试C代码
[xi'anjiaotonguniversity] information sharing of the first and second postgraduate entrance examinations
基于HAL库的LED驱动库
ArrayList and sequence table
LeetCode Algorithm 86. 分隔鏈錶
再测云原生数据库性能:PolarDB依旧最强,TDSQL-C、GaussDB变化不大
Handler source code analysis
LVGL 8.2 menu from a drop-down list
数据库什么时候需要使用索引【杭州多测师】【杭州多测师_王sir】
100 important knowledge points that SQL must master: updating and deleting data
国产自研系统的用户突破4亿,打破美国企业的垄断,谷歌后悔不迭