Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.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/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/2/google-app-engine/4.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,我首先使用aggregate获得数据帧中每列的平均值: meanDemVoteHouseState <- aggregate(congress$X2012.House.Dem.vote, by = list(state = congress$state), FUN = mean) 得到 'data.frame': 50 obs. of 2 variables:

我首先使用
aggregate
获得数据帧中每列的平均值:

meanDemVoteHouseState <- aggregate(congress$X2012.House.Dem.vote, 
                          by = list(state = congress$state),
                                   FUN = mean)
得到

'data.frame':   50 obs. of  2 variables:
 $ state: chr  "AK" "AL" "AR" "AZ" ...
 $ x    : num  0.29 0.34 0.29 0.462 0.566 ...
显然,新变量现在被称为“x”

但当我试着分类时:

meanDemVoteHouseState[order(x),]
我收到一个错误“找不到对象“x”

我尝试了很多其他的方法,但都没有效果

我错过了什么?

你想要什么

 meanDemVoteHouseState[order(meanDemVoteHouseState[,"x"]),]
如果你分两步来做的话,你会变得更清楚

 myind <- order(meanDemVoteHouseState[,"x"])   # need 'x' fully qualified
 meanDemVoteHouseState[myind, ]
myind你想要什么

 meanDemVoteHouseState[order(meanDemVoteHouseState[,"x"]),]
如果你分两步来做的话,你会变得更清楚

 myind <- order(meanDemVoteHouseState[,"x"])   # need 'x' fully qualified
 meanDemVoteHouseState[myind, ]

myind这样做可能更容易

meanDemVoteHouseState <- aggregate(X2012.House.Dem.vote ~ state,
                                   data = congress, FUN = mean)

意味着只做一件事可能会更容易些

meanDemVoteHouseState <- aggregate(X2012.House.Dem.vote ~ state,
                                   data = congress, FUN = mean)

meanDemVoteHouseState你能给出一个国会数据样本吗?
meanDemVoteHouseState[带(meanDemVoteHouseState,order(x)),]
meanDemVoteHouseState[带(meanDemVoteHouseState,order(x)),]你能给出一个国会数据样本吗?
meanDemVoteHouseState[带(meanDemVoteHouseState,order(x)),]
meanDemVoteHouseState[订单(meanDemVoteHouseState$x),]
谢谢。那也行。我可能会把变量名改成更合理的名称。谢谢。那也行。我可能最终会将变量名更改为更合理的名称。