当前位置:网站首页>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处理,进行重命名。
边栏推荐
- 8 lines of code to achieve quick sorting, easy to understand illustrations!
- LVGL 8.2 menu from a drop-down list
- 【STL源码剖析】容器(待补充)
- LVGL 8.2 Checkboxes as radio buttons
- [IC5000 tutorial] - 01- use daqdea graphical debug to debug C code
- [STL source code analysis] container (to be supplemented)
- 【leetcode 16】三数之和
- Go language defer
- 100 important knowledge points that SQL must master: Combined Query
- 蚂蚁金服笔试题:需求文档有什么可以量化的【杭州多测师】【杭州多测师_王sir】...
猜你喜欢
![[STL source code analysis] container (to be supplemented)](/img/69/0c6e0e8ecb3ebc8c9b8503f5a8b4e5.jpg)
[STL source code analysis] container (to be supplemented)

Time complexity and space complexity

科普达人丨漫画图解什么是eRDMA?

List介绍

It's time for the kotlin coroutine to schedule thread switching to solve the mystery

我们公司使用 7 年的这套通用解决方案,打通了几十个系统,稳的一批!

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

以PolarDB为代表的阿里云数据库以跻身全球第一阵营

时间复杂度与空间复杂度

导致系统性能失败的10个原因
随机推荐
MySQL导出sql脚本文件
ArrayList and sequence table
[leetcode 239] sliding window
LED driver library based on Hal Library
什么是微信小程序,带你推开小程序的大门
List介绍
训练一个图像分类器demo in PyTorch【学习笔记】
中移OneOS开发板学习入门
【IC5000教程】-01-使用daqIDEA图形化debug调试C代码
Problems and solutions in pyinstall packaging for pychart project
Classic interview question: responsible modules, how do you design test cases for these function points? [Hangzhou multi surveyors] [Hangzhou multi surveyors \wang Sir]
Oceanbase installation Yum source configuration error and Solutions
高通发布物联网案例集 “魔镜”、数字农业已经成为现实
Mathematics (fast power)
100 important knowledge points that SQL must master: creating and manipulating tables
8行代码实现快速排序,简单易懂图解!
LVGL 8.2 Drop down in four directions
我们公司使用 7 年的这套通用解决方案,打通了几十个系统,稳的一批!
Compression state DP bit operation
10天学会flutter DAY10 flutter 玩转 动画与打包