当前位置:网站首页>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处理,进行重命名。
边栏推荐
- 博弈论入门
- 单片机 MCU 固件打包脚本软件
- MCU firmware packaging Script Software
- LVGL 8.2 Checkboxes as radio buttons
- 电商两位大佬花边新闻刷屏,代表电商回归正常,将有利于实体经济
- LVGL 8.2 Simple Colorwheel
- 200000 bonus pool! [Alibaba security × ICDM 2022] the risk commodity inspection competition on the large-scale e-commerce map is in hot registration
- SQL必需掌握的100个重要知识点:分组数据
- [leetcode 16] sum of three numbers
- Kongsong (ICT Institute) - cloud security capacity building and trend in the digital age
猜你喜欢
![When does the database need to use the index [Hangzhou multi surveyors] [Hangzhou multi surveyors _ Wang Sir]](/img/2a/f07a7006e0259d78d046b30c761764.jpg)
When does the database need to use the index [Hangzhou multi surveyors] [Hangzhou multi surveyors _ Wang Sir]
![[STL source code analysis] container (to be supplemented)](/img/69/0c6e0e8ecb3ebc8c9b8503f5a8b4e5.jpg)
[STL source code analysis] container (to be supplemented)

go语言defer

Esp32-c3 introductory tutorial question ⑨ - core 0 panic 'ed (load access fault) Exception was unhandled. vfprintf. c:1528

记一次ViewPager + RecyclerView的内存泄漏

Kongsong (ICT Institute) - cloud security capacity building and trend in the digital age

The first China Digital Collection conference will be held soon

It's time for the kotlin coroutine to schedule thread switching to solve the mystery
![[机缘参悟-34]:光锥之内皆命运](/img/3e/9f5630ba382df7f7ce00705445cef8.jpg)
[机缘参悟-34]:光锥之内皆命运

Handler-源码分析
随机推荐
LVGL 8.2 re-coloring
SQL必需掌握的100个重要知识点:使用子查询
Create - configure factory
[机缘参悟-34]:光锥之内皆命运
sublist3r报错解决
The life, working principle and application of electrochemical oxygen sensor
Wechat Emoji is written into the judgment, and every Emoji you send may become evidence in court
科普达人丨漫画图解什么是eRDMA?
The reasoning delay on iphone12 is only 1.6 MS! Snap et al. Analyzed the transformer structure latency in detail, and used NAS to find out the efficient network structure of mobile devices
8行代码实现快速排序,简单易懂图解!
ARouter 最新问题合集
Wireguard simple configuration
SQL必需掌握的100个重要知识点:联结表
LVGL 8.2 Simple Image button
[STL source code analysis] container (to be supplemented)
Key library function based on Hal Library
100 important knowledge points that SQL must master: using subquery
Methods and usage of promise async and await
datax - 艰难debug路
[leetcode 16] sum of three numbers