Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Duncan Murdoch
On 14/12/2023 11:37 a.m., Martin Morgan wrote: In the spirit of 'advent of code', maybe it is better to exploit the features of the particular language you've chosen? Then the use of factors seems very relevant. value_levels <- c("Small", "Medium", "Large") df <- data.frame( person =

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Martin Morgan
In the spirit of 'advent of code', maybe it is better to exploit the features of the particular language you've chosen? Then the use of factors seems very relevant. value_levels <- c("Small", "Medium", "Large") df <- data.frame( person = c("Alice", "Bob", "Bob", "Charlie"), value =

[R] Suggestion for list - change reply-to

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
Hi, I suggest that reply-to is changed to r-help@r-project.org and not the original sender. The reason for my suggestion: I just made a mistake when replying to a message. I forgot to change the reply address from the sender to the r-help and I think that happens quite often for others

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
On Thu, 14 Dec 2023 at 12:02, Duncan Murdoch wrote: > > class(df$value) <- "sizeclass" > > `>.sizeclass` <- function(left, right) custom_sort(unclass(left), > unclass(right)) == 1 > > `==.sizeclass` <- function(left, right) custom_sort(unclass(left), > unclass(right)) == 0 > > `[.sizeclass` <-

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
> This sounds suspiciously like homework (which is off-topic... see the Posting > Guide) It is not homework. Currently I am trying to solve this: https://adventofcode.com/2023/day/7 But it is something that has puzzled me for a long time. In many programming languages, you can give a "less"

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Duncan Murdoch
On 14/12/2023 3:00 a.m., Martin Møller Skarbiniks Pedersen wrote: Hi, I need to sort a data.frame based on a custom sorting function. It is easy in many languages but I can't find a way to do it in R. In many cases I could just use an ordered factor but my data.frame contains poker

Re: [R] Sorting based a custom sorting function

2023-12-14 Thread Jeff Newmiller via R-help
This sounds suspiciously like homework (which is off-topic... see the Posting Guide), and you haven't indicated how you plan to encode your poker hands, and most core features of other languages are possible in R so if you really understand these other techniques and R then you should be able

[R] Sorting based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
Hi, I need to sort a data.frame based on a custom sorting function. It is easy in many languages but I can't find a way to do it in R. In many cases I could just use an ordered factor but my data.frame contains poker hands and I need to rank these hands. I already got a function that