Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 当一列为空时,如何对数据帧中的两列进行排序_R_Sorting - Fatal编程技术网

R 当一列为空时,如何对数据帧中的两列进行排序

R 当一列为空时,如何对数据帧中的两列进行排序,r,sorting,R,Sorting,因此,我尝试在我的数据帧中对ACCT\u NUM和ACCT\u DT进行排序,我使用以下步骤: ACCT_NUM ACCT_PURGED_FLG ACCT_PURGED_DT 1234 N 12345 N 3456 N 但是由于acct\u dt是空的,因此会抛出错误: 顺序错误(rdw_n$ACCT_NUM,rdw_n$ACCT_dt):参数2 不是向

因此,我尝试在我的数据帧中对
ACCT\u NUM
ACCT\u DT
进行排序,我使用以下步骤:

ACCT_NUM    ACCT_PURGED_FLG    ACCT_PURGED_DT
   1234                   N 
  12345                   N 
  3456                    N 
但是由于
acct\u dt
是空的,因此会抛出错误:

顺序错误(rdw_n$ACCT_NUM,rdw_n$ACCT_dt):参数2 不是向量


哪种可能的解决方案可以对这些变量进行排序,即使它们是空的或不是空的。

将空单元格替换为
NA
应使用(rdw_n,if(is.vector(ACCT_pulled_DT))rdw_n[顺序(ACCT_NUM,ACCT_pulled_DT),]否则rdw_n[顺序(ACCT_NUM),]
rdw_n> rdw_n[with(rdw_n, order(rdw_n$ACCT_NUM, rdw_n$acct_purged_dt)), ]