在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 variablecoef
. 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
最满意答案
我通常在我的帽子部署上做的是创建目录,通过做一个基本的
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 anafter
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 ...
-
使用Rails + Capistrano与Github和多个分支(Using Rails + Capistrano with Github and multiple branches)[2023-04-02]
我不会使用单独的分支进行开发和生产。 我会做一个“实验性”分支。 一个分支真的被设计成一个安全的地方,在那里你可以脱离你的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 ...
-
Apache2,Git,Capistrano和Rails - 创建符号链接(Apache2, Git, Capistrano & Rails - creating symlinks)[2023-04-27]
我通常在我的帽子部署上做的是创建目录,通过做一个基本的 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 ... -
通过Capistrano部署时未加载Rails ActiveSupport(Rails ActiveSupport not loaded when deploying via Capistrano)[2022-02-11]
原来这与在我的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.