当前位置:网站首页>Select function variable column name in dplyr of R language
Select function variable column name in dplyr of R language
2022-07-04 04:27:00 【Analysis of breeding data】
Background introduction :
R In language , Data frame column names are standardized , Here I want to extract Y2:Y11, Q1:Q5 Such column names , I don't want to write a complete column name ,
Generate a variable name outside, including the above content , such as :
n1 = str_c("Y",2:11)
n1
n2 = str_c("Q",1:5)
n2
And then directly according to n1,n2 Content to extract .
Problem solving
library(dplyr)
dd %>% select(n1,n2) %>% head

With a prefix bug, If there is n1 and n2 Column name of , The above data becomes :
dd$n1 = rnorm(44)
dd$n2 = rnorm(44)
library(dplyr)
dd %>% select(n1,n2) %>% head

obviously , This is not what we want .
Better solution
use
dplyrMediumall_offunction , Use the contents of variables , Instead of the original name of the variable :
dd %>% select(all_of(n1),all_of(n2)) %>% head

This is a more appropriate plan .
Problem solving !
边栏推荐
- Redis:有序集合zset类型数据操作命令
- Touch and take you to implement an EventEmitter
- RHCSA 04 - 进程管理
- Unity draws the trajectory of pinball and billiards
- Modstartblog modern personal blog system v5.2.0 source code download
- 【安全攻防】序列化与反序列,你了解多少?
- 2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
- Leader: who uses redis expired monitoring to close orders and get out of here!
- 干货!基于GAN的稀有样本生成
- (pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
猜你喜欢

干货!基于GAN的稀有样本生成

5张图告诉你:同样是职场人,差距怎么这么大?

【云原生】那些看起来很牛X,原理却很简单的一行代码

Flink learning 8: data consistency

Leetcode skimming: binary tree 09 (minimum depth of binary tree)

Flink learning 6: programming model

软件测试是干什么的 发现缺陷错误,提高软件的质量

Global exposure and roller shutter exposure of industrial cameras

深入解析结构化异常处理(SEH) - by Matt Pietrek

资深开发人员告诉你,怎样编写出优秀的代码?
随机推荐
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
[webrtc] M98 Ninja build and compile instructions
北漂程序员,月薪20K,一年攒15W,正常吗?
[microservices openfeign] two degradation methods of feign | fallback | fallbackfactory
苹果CMS仿西瓜视频大气响应式视频模板源码
Unity Resource path
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
微信公众号无限回调授权系统源码
Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
Flink学习7:应用程序结构
ROS2中CMake编译选项的设置
博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
【微服务|openfeign】@FeignClient详解
领导:谁再用redis过期监听实现关闭订单,立马滚蛋!
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
Flink学习8:数据的一致性
Interpretation of leveldb source code skiplist
如何远程办公更有效率 | 社区征文
(指针)编写函数void fun(int x,int *pp,int *n)
深入解析结构化异常处理(SEH) - by Matt Pietrek