通过R中的变量订购数据,我缺少什么? [英] Order data by variable in R, what am I missing?

查看:66
本文介绍了通过R中的变量订购数据,我缺少什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以一种特定的方式订购我的数据.我在data.a中引入了一个变量"Index",并将其与data.b合并.之后,合并数据的顺序不正确,因此我想按索引再次对其进行排序. 我合并的数据如下:

I would like to order my data in a specific way. I introduced a variable "Index" in data.a and merged it with data.b. Afterwards the merged data is not in the right order, so I would like to order it again by the Index. My merged Data looks like:

> str(aksamp.mer)
'data.frame':   11355 obs. of  6 variables:
 $ V    : Factor w/ 78 levels "","V1-18","V1-2",..: 3 23 49 49 17 41 10 10 40 39 ...
 $ J    : Factor w/ 7 levels "","J1","J2","J3",..: 5 5 5 5 5 5 7 7 6 7 ...
 $ D    : Factor w/ 28 levels "","D1-1","D1-14",..: 3 23 7 7 22 22 18 18 8 9 ...
 $ Class: Factor w/ 1 level "IgG": 1 1 1 1 1 1 1 1 1 1 ...
 $ Count: int  63 59 1 58 52 50 49 7 43 41 ...
 $ Index: int  1051 10318 3218 3218 9887 9929 7503 7503 2438 3767 ...

我正在尝试通过索引"列再次对data.frame重新排序:

I am trying to reorder the data.frame again by the column "Index":

> aksamp.mer2<-aksamp.mer[order(Index),]

这给我一个错误:找不到对象'索引'.我在做什么错了?

which gives me the Error: "object 'Index' not found. What am I doing wrong?

推荐答案

它正在抱怨您的环境中没有Index对象.正确的访问方法是使用aksamp.mer$Index.因此,您需要这样做:

It is complaining that there is no Index object in your environment. The right way to access it is to use aksamp.mer$Index. So you need to do:

aksamp.mer2 <-aksamp.mer[order(aksamp.mer$Index), ]

这篇关于通过R中的变量订购数据,我缺少什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆