首页 \ 问答 \ 在data.frame中进行双重排序(Double sorting in data.frame)

在data.frame中进行双重排序(Double sorting in data.frame)

我有一个data.frame需要双重排序,其中的一部分如下

       PERMNO   mktcap      coef
13974  11711  37.5000 1.2508261
24798  13071  72.8750 0.7413084
15294  11869  75.0000 0.3820783
33114  14170 111.3750 2.3607454
24270  13004 131.2500 4.0205943
37866  14699 131.2500 1.8548012
32190  13995 135.0000 1.7028044
30078  13768 149.2500 1.3376186
28494  13530 150.0000 1.7675992
27966  13469 188.1250 1.3499105
16350  12001 210.3750 1.7627097
30870  13848 225.0000 1.7692176
29154  13581 272.2500 1.6714913
33906  14277 309.3750 2.0797843
39186  14816 322.8750 1.6204331
7638   10911 332.7500 1.0864174
9882   11201 339.0000 1.8405390
38922  14787 363.1250 0.9696966
40638  15018 376.8750 1.5077336
34302  14306 411.7500 1.4610924
8298   11017 453.1250 2.0834445
40770  15034 528.9375 2.3746428
33774  14269 531.3750 2.0195085
32322  14007 560.6250 1.7508435
45258  15560 572.0625 2.2281513
10806  11332 577.5000 1.3420006
30342  13784 593.1250 2.0868992
22026  12722 596.7500 1.2661233
12918  11535 640.0000 2.3642444
43014  15253 641.2500 0.8406199

我需要将所有观察分成100个组。 该过程包括两个步骤:首先,根据变量mktcap的值将所有观测值划分为10个观测值相等的观​​测值; 第二,对于每个组,进一步将一组内的观察结果划分为10组,其中变量coef的值具有相同的观察值。 然后添加一个新变量,指出每个观察的组。 此新变量的值应在p1到p100之间。


I have a data.frame that needs double-sorting, part of it is as below

       PERMNO   mktcap      coef
13974  11711  37.5000 1.2508261
24798  13071  72.8750 0.7413084
15294  11869  75.0000 0.3820783
33114  14170 111.3750 2.3607454
24270  13004 131.2500 4.0205943
37866  14699 131.2500 1.8548012
32190  13995 135.0000 1.7028044
30078  13768 149.2500 1.3376186
28494  13530 150.0000 1.7675992
27966  13469 188.1250 1.3499105
16350  12001 210.3750 1.7627097
30870  13848 225.0000 1.7692176
29154  13581 272.2500 1.6714913
33906  14277 309.3750 2.0797843
39186  14816 322.8750 1.6204331
7638   10911 332.7500 1.0864174
9882   11201 339.0000 1.8405390
38922  14787 363.1250 0.9696966
40638  15018 376.8750 1.5077336
34302  14306 411.7500 1.4610924
8298   11017 453.1250 2.0834445
40770  15034 528.9375 2.3746428
33774  14269 531.3750 2.0195085
32322  14007 560.6250 1.7508435
45258  15560 572.0625 2.2281513
10806  11332 577.5000 1.3420006
30342  13784 593.1250 2.0868992
22026  12722 596.7500 1.2661233
12918  11535 640.0000 2.3642444
43014  15253 641.2500 0.8406199

I need to divide all observations into 100 groups. The procedure involves two steps: first, divide all observations into 10 groups with equal observations in terms of the value of the variable mktcap; second, for each group, further divided the observations within a group into 10 groups with equal observations in terms of the value of the variable coef. Then add a new variable indicating the group of each observation. The value of this new variable should range from p1 to p100.


原文:https://stackoverflow.com/questions/39782657
更新时间:2024-02-08 21:02

最满意答案

我通常在我的帽子部署上做的是创建目录,通过做一个基本的

set :deploy_to, "/this/dir"

run "mkdir -p #{deploy_to}/then/more/dirs"

after "deploy:symlink"

namespace :deploy....
  ....
  ....

然后提供run代码,以便在after或者其他内容上做一些符号链接。 这可能不是所有情况下的最佳选择,但对于简单的东西,它通常可以完成工作。


What I'll usually do on my cap deploys is to create the directories, by doing a basic

set :deploy_to, "/this/dir"

run "mkdir -p #{deploy_to}/then/more/dirs"

after "deploy:symlink"

namespace :deploy....
  ....
  ....

then provide the run code to do some symlinks either on an after or whatever. This probably not optimal for all situations, but for the simple stuff it usually gets the job done.

相关问答

更多
  • 我的猜测是,因为您手动在CI环境中安装Capistrano Gems,所以存在版本不匹配。 如果您在CI服务器上运行bundle install和bundle exec ,或者固定安装的版本,它可能会开始工作。 我用过的一个解决方案是将所有必需的部署gem添加到我的Gemfile中的一个:deployment组中。 然后,您需要将以下内容添加到您的deploy.rb : set :bundle_without, %w{development test deployment}.join(' ') 然后将您的 ...
  • 问题是我的执行声明: execute 'git clone git@github.com:username/my_gem.git', gem_path 我改成了 execute "git clone git@github.com:username/my_gem.git #{gem_path}" 它现在按预期工作。 The issue was my execute statement: execute 'git clone git@github.com:username/my_gem.git', gem_ ...
  • 是的,mercurial支持几种分支模型克隆可能是最常见的。 这听起来像是对我命名分支的理想使用,但它最终是个人喜好的事情 yes mercurial supports several branching models cloning is probably the most common. this certainly sounds like the ideal use of a named branch to me, but its ultimately a personal preference th ...
  • 我不会使用单独的分支进行开发和生产。 我会做一个“实验性”分支。 一个分支真的被设计成一个安全的地方,在那里你可以脱离你的master (你的工作代码),并尝试一些实验。 所以真正的master 是你的生产分支,开发是你从中做出的任何分支。 当您在其他分支上进行更改时,请提交它们,然后使用 git checkout master git merge newbranch 将newbranch合并到您的主人。 I would not use separate branches for development ...
  • 我终于成功了。 有关XSendFile问题的一些提示 我将XSendFilePath设置为用户的$HOME ,在$HOME的路径上没有符号链接,因此它可以工作。 我可以从功能和安全的角度来接受这一点,但这显然是一种解决方法。 请注意, XSendFilePath对包含多个斜杠/like//this路径敏感。 我正在使用apache宏,并在从几个宏参数连接XSendFilePath参数时,我放了一些过时的斜杠。 这导致XSendFile拒绝发送文件。 祝你好运! I finally managed to ma ...
  • 角色Web,应用程序和数据库需要是您要部署到的服务器的URL或IP。 像这样的东西: task :staging do set :rails_env, 'staging' role :app, "example.com" role :web, "example.com" role :db, "example.com", :primary => true end Role web, app and db need to be the URL or IP of the server that ...
  • Capistrano为每个版本的realeases创建一个新的子目录 horse:releases xxx$ ls -lart total 0 drwxrwxr-x 22 xxx staff 748 Jun 26 20:08 20120626180809 drwxrwxr-x 22 xxx staff 748 Jun 26 20:11 20120626181103 drwxrwxr-x 22 xxx staff 748 Jun 26 20:29 20120626182908 drwxrwx ...
  • 最终,我能够使用符号链接获得有效的配置 - 它可以在克隆和推送中运行。 这个人的帖子非常有帮助: 如何在http上设置git? 启用符号链接后我也重新访问了符号链接选项(来自@ 1615903的提醒 - 谢谢),然后对权限进行了一些故障排除。 最后一个难题是将用户和组设置的域驱动器安装到Apache的。 我以前只是使用组合装载,继续使用官方git-scm手册中的chgrp建议。 似乎这还不足以获得稳健的行为...... Ultimately I was able to get a working confi ...
  • 我通常在我的帽子部署上做的是创建目录,通过做一个基本的 set :deploy_to, "/this/dir" run "mkdir -p #{deploy_to}/then/more/dirs" after "deploy:symlink" namespace :deploy.... .... .... 然后提供run代码,以便在after或者其他内容上做一些符号链接。 这可能不是所有情况下的最佳选择,但对于简单的东西,它通常可以完成工作。 What I'll usually do on ...
  • 原来这与在我的application.rb文件中使用90.minutes有关。 我仍然不知道为什么这适用于开发而不是生产。 Turns out this had to do with using 90.minutes in my application.rb file. I still don't know why this works on dev and not production.

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。