[R] Sorting

Don MacQueen macq at llnl.gov
Sat Feb 6 21:00:10 CET 2010


I have trouble making sense of the question, and I wonder if there is 
a terminology issue.

For example, you have a list like this one:

   mylist <- list( v1=1:3, v2=1:4, v3=1:5, v4=1:6)

(That is, a list of vectors of varying lengths.)

You want to apply a function to each pair of vectors:
   First to v1 and v2,
   Then to v2 and v3,
   Then to v3 and v4
?
And also to pairs v1 and v3, v1 and v4, and so on?

Which one is larger, mylist$v1 or mylist$v2? Longer, yes, mylist$v2 
is longer. But larger?

And ultimately you want to have the list with its elements in some other order,
perhaps v4 comes first, then v3, and so on?

-Don


At 1:21 PM -0500 2/6/10, David Neu wrote:
>Hi,
>
>I have a list of vectors (of varying lengths).  I'd like to sort this
>list by applying a function to each pair of vectors in the list and
>returning information to sorting routine that let's it know which one
>is larger.
>
>To solve problems like this in Common Lisp, the sort function accepts
>a function as an argument.  The arguments to this function are two
>elements of the list which is being sorted.  The writer of the
>function returns t (TRUE in R) when the first argument to the function
>is larger than the second and nil (FALSE in R) otherwise.
>
>I'm wondering if there is some way to accomplish this in R.
>
>Many thanks for any help!
>
>Cheers,
>David
>
>______________________________________________
>R-help at r-project.org mailing list
>https://*stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062



More information about the R-help mailing list