Re: [R] Subset and order

2013-07-07 Thread arun
. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Noah Silverman noahsilver...@ucla.edu Cc: R-help@r-project.org r-help@r-project.org Sent: Friday, July 5, 2013 3:51 PM Subject: Re: [R] Subset and order Hello, If time is one of the problems, precompute an ordered index, and use

[R] Subset and order

2013-07-05 Thread Noah Silverman
Hello, I have a data frame with several columns. I'd like to select some subset *and* order by another field at the same time. Example: a b c 1 2 3 3 3 4 2 4 5 1 3 4 etcÂ… I want to select all rows where b=3 and then order by a.

Re: [R] Subset and order

2013-07-05 Thread Rui Barradas
Hello, Maybe like this? subset(x[order(x$a), ], b == 3) Hope this helps, Rui Barradas Em 05-07-2013 20:33, Noah Silverman escreveu: Hello, I have a data frame with several columns. I'd like to select some subset *and* order by another field at the same time. Example: a b c

Re: [R] Subset and order

2013-07-05 Thread Noah Silverman
That would work, but is painfully slow. It forces a new sort of the data with every query. I have 200,000 rows and need almost a hundred queries. Thanks, -N On Jul 5, 2013, at 12:43 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Maybe like this? subset(x[order(x$a), ], b == 3)

Re: [R] Subset and order

2013-07-05 Thread Rui Barradas
Hello, If time is one of the problems, precompute an ordered index, and use it every time you want the df sorted. But that would mean you can't do it in a single operation. iord - order(x$a) subset(x[iord, ], b == 3) Rui Barradas Em 05-07-2013 20:47, Noah Silverman escreveu: That would

Re: [R] Subset and order

2013-07-05 Thread David Carlson
[mailto:r-help-boun...@r-project.org] On Behalf Of Noah Silverman Sent: Friday, July 5, 2013 2:47 PM To: Rui Barradas Cc: R-help@r-project.org Subject: Re: [R] Subset and order That would work, but is painfully slow. It forces a new sort of the data with every query. I have 200,000 rows and need

Re: [R] Subset and order

2013-07-05 Thread Ben Bolker
David Carlson dcarlson at tamu.edu writes: It may be that single and efficient are opposing goals. Two steps lets you create the subset and then just order each query. Alternatively, if the data do not change often, create an ordered version and query that. I don't know the data.table

[R] Subset and order at the same time?

2012-05-12 Thread Noah Silverman
Is there a way to order data and subset it at the same time?? I want to sort all the members of group A by their values in column 3. (I'll then do the same for each subsequent group.) This could be done in a loop building up another vector, but I like to avoid loops in R.

Re: [R] Subset and order at the same time?

2012-05-12 Thread Berend Hasselman
On 12-05-2012, at 20:04, Noah Silverman wrote: Is there a way to order data and subset it at the same time?? I want to sort all the members of group A by their values in column 3. (I'll then do the same for each subsequent group.) This could be done in a loop building up another

Re: [R] Subset and order at the same time?

2012-05-12 Thread Noah Silverman
Bernard, Thanks, but I can't take that shortcut. The data is an xts object, and I may not want to order every group. So, I need a way to just order one group at a time. Thoughts? -- Noah Silverman UCLA Department of Statistics 8208 Math Sciences Building Los Angeles, CA 90095 On May 12,

Re: [R] Subset and order at the same time?

2012-05-12 Thread jim holtman
Just write a function so that you have a one-liner in your script. It will probably be a lot simpler than trying to type some convoluted one-liner. On Sat, May 12, 2012 at 2:58 PM, Noah Silverman noahsilver...@ucla.edu wrote: Bernard, Thanks, but I can't take that shortcut. The data is an

Re: [R] Subset and order at the same time?

2012-05-12 Thread Neal Fultz
can be done in one line, but it is annoying and ugly, so you probably shouldn't be doing it that way: sleep[sleep$group == 1,] -sleep[sleep$group == 1,][order(sleep[sleep$group == 1,1]),] sleep extra group ID 1 -1.6 1 2 2 -1.2 1 4 3 -0.2 1 3 4 -0.1 1 5 50.0

Re: [R] Subset and order at the same time?

2012-05-12 Thread Joshua Wiley
Hi Noah, I think it is hard to say what is best without your real example. Is the goal elegance or speed? I have not tried it, but if you are ordering say 9/10 groups, I would think you are better off calling order once, even though you will not use it for one group. I also think if you are