Reordering the columns in a data frame
Problem
You want to do reorder the columns in a data frame.
Solution
# A sample data frame
data <- read.table(header=TRUE, text='
id weight size
1 20 small
2 27 large
3 24 medium
')
# Reorder by column number
data[c(1,3,2)]
#> id size weight
#> 1 1 small 20
#> 2 2 large 27
#> 3 3 medium 24
# To actually change `data`, you need to save it back into `data`:
# data <- data[c(1,3,2)]
# Reorder by column name
data[c("size", "id", "weight")]
#> size id weight
#> 1 small 1 20
#> 2 large 2 27
#> 3 medium 3 24
REF:
http://www.cookbook-r.com/Manipulating_data/Reordering_the_columns_in_a_data_frame/
Reordering the columns in a data frame的更多相关文章
- keep or remove data frame columns in R
You should use either indexing or the subset function. For example : R> df <- data.frame(x=1:5 ...
- R语言 data.frame 大全
A data frame is used for storing data tables. It is a list of vectors of equal length. For example, ...
- R class of subset of matrix and data.frame
a = matrix( c(2, 4, 3, 1, 5, 7), # the data elements nrow=2, # number of rows ...
- How do I extract a single column from a data.frame as a data.frame
Say I have a data.frame: df <- data.frame(A=c(10,20,30),B=c(11,22,33), C=c(111,222,333)) A B C ...
- R语言合并data.frame
Merging Data Adding Columns To merge two data frames (datasets) horizontally, use the merge functio ...
- R vs Python:构建data.frame、读取csv与统计描述
一.Python 数据框就是典型的关系型数据库的数据存储形式,每一行是一条记录,每一列是一个属性,最终构成表格的形式,这是数据科学家必须熟悉的最典型的数据结构. 1.构建数据框 import pand ...
- R Data Frame
https://www.datamentor.io/r-programming/data-frame/ Check if a variable is a data frame or not We ca ...
- AE开发能否实现TOC Control里添加多个Data Frame
问题: 在ArcMap中,菜单Insert下Data Frame,可以在TOC中增加Data Frame,在MapControl或者PageLayoutControl下都可以正常显示多个Data Fr ...
- R语言Data Frame数据框常用操作
Data Frame一般被翻译为数据框,感觉就像是R中的表,由行和列组成,与Matrix不同的是,每个列可以是不同的数据类型,而Matrix是必须相同的. Data Frame每一列有列名,每一行也可 ...
随机推荐
- hadoop集群搭建实践
一.Linux配置1.设置hosts的ip(集群机器做同样操作)vi /etc/hosts192.168.91.129 master192.168.91.130 slave #互相ping通即可 pi ...
- VS2015中运行ASPX老项目出错HTTP Error 500.23 - Internal Server Error错误
今天翻出以前用VS2010做的老项目,在VS2015中运行ASPX页面浏览,出现错误: HTTP Error 500.23 - Internal Server Error 检测到在集成的托管管道模式下 ...
- error: unpacking of archive failed on file /usr/sbin/zabbix_agent;592e5bc3: cpio: open
# lsattr /usr/ ----------I--e- /usr/lib64 ----------I--e- /usr/bin -------------e- /usr/libexec ---- ...
- HTML5学习笔记(八):CSS定位
CSS 定位 (Positioning) 属性允许你对元素进行定位. 定位和浮动 CSS 为定位和浮动提供了一些属性,利用这些属性,可以建立列式布局,将布局的一部分与另一部分重叠.定位的基本思想很简单 ...
- FFmpeg(14)-使用NDK、C++完成EGL,display, surface, context的配置和初始化
EGL 用它开发需要做哪些事情. DIsplay 与原生窗口建立链接.EGL在Android中可以用java调,也可以用C++调. EGLDisplay eglGetDisplay ...
- angular学习笔记(三十)-指令(2)-restrice,replace,template
本篇主要讲解指令中的 restrict属性, replace属性, template属性 这三个属性 一. restrict: 字符串.定义指令在视图中的使用方式,一共有四种使用方式: 1. 元素: ...
- 每日英语:How Your Knees Can Predict the Weather
The Wolff family of Paramus, N.J., was eyeing the gathering clouds and debating whether to cancel a ...
- 【驱动】linux设备驱动·入门
linux设备驱动 驱动程序英文全称Device Driver,也称作设备驱动程序.驱动程序是用于计算机和外部设备通信的特殊程序,相当于软件和硬件的接口,通常只有操作系统能使用驱动程序. 在现代计算机 ...
- html5+css3比较好的学习教程和demo效果
1.css3 Animate.css 动画库--- http://daneden.github.io/animate.css/ 2.font-awesome 完美的图标字体,只为Bootstrap设计 ...
- 通用后台管理系统(ExtJS 4.2 + Spring MVC 3.2 + Hibernate)
通用后台管理系统(ExtJS 4.2 +Spring MVC 3.2 + Hibernate) 开发语言JAVA 成品成品 前端技术extjs 数据库mysql,sql server,oracle 系 ...