当前位置:网站首页>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
dplyr
Mediumall_of
function , 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 !
边栏推荐
- Detailed explanation of event cycle
- Senior developers tell you, how to write excellent code?
- 领导:谁再用redis过期监听实现关闭订单,立马滚蛋!
- EIG在智利推出可再生能源平台Grupo Cerro
- leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
- C语言双向链表初版
- Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
- R语言dplyr中的Select函数变量列名
- How to add custom API objects in kubernetes (1)
- 【微信小程序】好看的轮播图组件
猜你喜欢
DP83848+网线热拔插
Emlog user registration plug-in is worth 80 yuan
The difference between bagging and boosting in machine learning
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
干货!基于GAN的稀有样本生成
Unity 绘制弹球和台球的运动轨迹
Parameterization of controls in katalon
RPC技术
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
Imitation of "game bird" source code, mobile game issue evaluation, open service, open test collection, game download website template
随机推荐
指针数组和数组指针
【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
Restore the subtlety of window position
架构实战营 - 第 6 期 模块九之毕业设计
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
一个漂亮的API文档生成工具
Three years of graduation, half a year of distance | community essay solicitation
[webrtc] M98 Ninja build and compile instructions
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
线程常用的方法
I.MX6U-ALPHA开发板(模仿STM32驱动开发实验)
VIM add interval annotation correctly
leetcode刷题:二叉树08(N叉树的最大深度)
毕业设计项目
多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
Flink learning 8: data consistency
EventBridge 在 SaaS 企业集成领域的探索与实践
Asynchronous development process - touch your hand and lead you to realize a promise
【微服务|openfeign】@FeignClient详解
The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)