首页 > 其他分享 >Reordering the columns in a data frame

Reordering the columns in a data frame

时间:2023-11-06 16:02:53浏览次数:39  
标签:weight frame Reordering data id columns size

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/



标签:weight,frame,Reordering,data,id,columns,size
From: https://blog.51cto.com/emanlee/8213338

相关文章

  • In R, how to split/subset a data frame by factors in one column?
    按照某列的值拆分data.frame Mydataislikethis(forexample):IDRateState124AL235MN346FL434AL578MN699FLIwanttosplitthedatabystateandIwanttoget3datasetslikebelow:dataset1IDRateState124AL......
  • JS对象文档 - FormData
    前言FormData接口提供了一种表示表单数据的键值对key/value的构造方式,并且可以轻松的将数据通过XMLHttpRequest.send()方法发送出去,本接口和此方法都相当简单直接。如果送出时的编码类型被设为"multipart/form-data",它会使用和表单一样的格式。正文构造函数constformDat......
  • PigVar: THE PIG VARIATIONS AND POSITIVE SELECTION DATABASE
    URL: http://www.ibiomedical.net/ http://103.53.216.7/Gotoaldbdatabase.(keywords:chicken,cow,pig;lincRNAs;expression;blast)ALDB:adomestic-animallongnoncodingRNAdatabase GotomiRBonddatabase.(keywords:pig,chicken,cow,targetscan,miRand......
  • 漏扫 X-Content-Type-Options X-XSS-Protection Strict-Transport-Security X-Fram
    web应用nginx部署未设置头部,导致可能出现安全问题【未设置X-Content-Type-Options响应头】【未设置X-XSS-Protection响应头】【未设置Strict-Transport-Security响应头】【X-Frame-Options头未设置】 Content-Type(内容类型),一般是指网页中存在的Content-Type,用于定义网络文......
  • How can I move a MySQL database from one server to another?
     Myfavoritewayistopipeasqldumpcommandtoasqlcommand.Youcandoalldatabasesoraspecificone.So,forinstance,mysqldump-uuser-ppasswordmyDatabase|mysql-hremoteserver-uremoteuser-premoteserverpasswordYoucandoalldatabaseswithmysq......
  • 解决适用EntityFramework生成时报错“无法解析依赖项。"EntityFramework 6.4.4" 与 '
    点击添加,出现错误提示:......
  • Human disease database
      https://www.malacards.org/    https://www.uniprot.org/uniprot/ https://www.genome.jp/kegg/disease/ ......
  • [936] Save a GeoDataFrame as a Shapefile
    InGeoPandas,youcansaveaGeoDataFrameasaShapefileusingtheto_filemethod.Here'showtodoit:importgeopandasasgpd#CreateorloadaGeoDataFrame(gdf)thatyouwanttosave#...#SpecifythepathandnamefortheShapefile(e.g.,&......
  • datasophon安装问题
    1.节点检测成功,部分节点部署失败,但是部署失败的节点agent进程启动成功   检查网络没有问题,查看manager日志没有问题,检查agent日志,发现提示连接管理节点失败,提示未知机器名称,经查看是hosts配置的管理节点映射名称有误,检查所有失败节点,修正hosts后部署成功。2.agent部署成......
  • (十)Robot Framework之处理接口响应
    处理响应数据1.获得响应正文${响应结果.content}二进制编码${响应结果.text}unicode码形式的正文${响应结果.content.decode("utf-8")}转码为utf-82.json格式${json变量} tojson ${响应结果.content} pretty_print=True获取json中的的项(相当于正则提取器)${变......