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每一列有列名,每一行也可 ...
随机推荐
- Android设计元素-操作栏
原文链接:http://android.eoe.cn/topic/android_sdk 操作栏 - Action Bar “操作栏”对于 Android 应用来说是最重要的设计元素.它通常在应用运行 ...
- [svc]linux启动过程及级别
Unix目录结构的来历 Linux 的启动流程 Linux 引导过程内幕 嵌入式系统 Boot Loader 技术内幕 centos6使用chkconfig治理服务和其原理 centos7的服务治理- ...
- 【Android】1.1 开发环境安装和配置
分类:C#.Android.VS2015: 创建日期:2016-01-20 2016-08-03说明:此版本已过时,最新版本见本博客置顶的内容. 一.安装JDK.SDK.NDK 无论是用C#和VS20 ...
- android: getDimension, getDimensionPixelOffset 和getDimensionPixelSize 区别
◆结论: getDimension 获取某个dimen的值,如果是dp或sp的单位,将其乘以density,如果是px,则不乘 返回float getDimensionPixelOffset 获取 ...
- python(36):python日志打印,保存,logging模块学习
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...
- hive外部表删除遇到的一个坑
hive外部表删除遇到的一个坑 操作步骤 创建某个表(create external table xxx location xxx) 插入数据(insert xxx select xxx from x ...
- Android下基于SDL的YUV渲染
实战篇 本文主要参考我之前整理的文章windows下使用SDL进行YUV渲染. 相对于之前写的位图渲染部分(http://www.cnblogs.com/tocy/p/android-sdl-bitm ...
- 【转】MySQL中information_schema是什么
大家在安装或使用MYSQL时,会发现除了自己安装的数据库以外,还有一个information_schema数据库. information_schema数据库是做什么用的呢,使用WordPress博客 ...
- ElasticSearch5.3安装head插件及连接ElasticSearch
1. 安装插件head # 去github上下载head git clone git://github.com/mobz/elasticsearch-head.git # 由于head基于nodejs ...
- Leetcode:Longest Substring Without Repeating Characters 解题报告
Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...