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每一列有列名,每一行也可 ...
随机推荐
- 在eclipse 导入简单的Android studio 简单项目
前言: 现在Android studio版本已经去到2.0(我暂时用着开发者版本)了,但是还是和以前的版本一样卡. (因为我用了很多第三方的UI控件,导致在Android studio build一个 ...
- [svc][jk]磁盘的iops和吞吐量(Throught)指标
参考 另参考 IOPS (Input/Output Per Second)即每秒的输入输出量(或读写次数),是衡量磁盘性能的主要指标之一.IOPS是指单位时间内系统能处理的I/O请求数量,一般以每秒处 ...
- PostgreSQL PL/Python 和 PL/Postgres 函数互相调用
create or replace function hello(name text) returns text as $$ # str = name+',你吃饭了吗?'; # return 'hel ...
- android 覆盖安装问题
1.android中覆盖安装不会导致data/data/package下的数据被删除 2.数据库会有数据库的一套升级机制 3.sharepreference 不会被覆盖,如果在app中有使用Key记录 ...
- 6 Multi-Cloud Architecture Designs for an Effective Cloud
https://www.simform.com/multi-cloud-architecture/ Enterprises increasingly want to take advantage of ...
- (原) windows下autohotkey的快捷键脚本编写
autohotkey 脚本很强大,可以接受传参.能各种程序逻辑控制.还可以把脚本转换成独立执行的EXE.(安装完后程序目录下有个小程序:Convert .ahk to .exe,直接UI上转换.)总之 ...
- 【Acm】算法之美—Jugs
题目概述:Jugs In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted wi ...
- Java编译命令整理
引言 近期在做Android相关开发工作,不可避免的需要接触Java层的调用机制,好多年不用Java了,这里整理下相关的编译命令.作为后续参考使用,也防止每次都需要到处查找. 基本概念 javac - ...
- 安装VCSA6.5(vCenter Server Appliance 6.5)
相关文章:http://www.ctoclubs.com/?p=756 一.简介 VCSA(vCenter Server Appliance 6.5),相对于Windows版本的vCenter,VCS ...
- 在Windows上弄一个redis的docker容器
[本文出自天外归云的博客园] Docker核心概念简介 镜像是一个面向docker引擎的只读模板,包含了文件系统. 镜像是创建容器的基础,容器类似于一个沙箱,用来运行和隔离应用. 容器是从镜像创建的应 ...