Re: [R] Is there a sexy way ...?

2024-09-30 Thread peter dalgaard
Yes, unsplit() it is. I was messing around with ave() (which can be hammered into submission, sort of). My overlooking unsplit() is somewhat impressive in view of "svn diff -c 18591" -pd > On 27 Sep 2024, at 17:08 , Martin Maechler wrote: > >> Chris Evans via R-help >>on Fri

Re: [R] Is there a sexy way ...?

2024-09-28 Thread Richard O'Keefe
gt; Sent: Saturday, September 28, 2024 10:11 PM > To: CALUM POLWART > Cc: avi.e.gr...@gmail.com; Lennart Kasserra ; > r-help@r-project.org > Subject: Re: [R] Is there a sexy way ...? > > > > On Sat, 28 Sep 2024 10:26:31 +0100 > CALUM POLWART wrote: > > > Avi >

Re: [R] Is there a sexy way ...?

2024-09-28 Thread avi.e.gross
ringr packages to make my silly version ever less silly! LOL! -Original Message- From: Rolf Turner Sent: Saturday, September 28, 2024 10:11 PM To: CALUM POLWART Cc: avi.e.gr...@gmail.com; Lennart Kasserra ; r-help@r-project.org Subject: Re: [R] Is there a sexy way ...? On Sat, 28 Sep 2024

Re: [R] Is there a sexy way ...?

2024-09-28 Thread Rolf Turner
On Sat, 28 Sep 2024 10:26:31 +0100 CALUM POLWART wrote: > Avi > > I fear this was all a huge social experiment. > > Testing if a post titled "sexy way" would increase engagement... I conjecture that this conjecture was tongue-in-cheek. Be that as it were 😊️, let me assure everyone that s

Re: [R] Is there a sexy way ...?

2024-09-28 Thread avi.e.gross
ct sense. Others are happier with a while(True) construct that makes clear the contents will decide when to break out. To expect people to agree on what is "sexy" is not a reasonable expectation. LOL! -Original Message----- From: Sorkin, John Sent: Saturday, September 28, 2024 12:01

Re: [R] Is there a sexy way ...? Fortune nomination

2024-09-28 Thread Achim Zeileis via R-help
On Sat, 28 Sep 2024, J C Nash wrote: On 2024-09-28 13:57, avi.e.gr...@gmail.com wrote: Python users often ask if a solution is “pythonic”. But I am not aware of R users having any special name like “R-thritic” and that may be a good thing. Nice, added on R-Forge :-) Achim __

Re: [R] Is there a sexy way ...? Fortune nomination

2024-09-28 Thread J C Nash
On 2024-09-28 13:57, avi.e.gr...@gmail.com wrote: Python users often ask if a solution is “pythonic”. But I am not aware of R users having any special name like “R-thritic” and that may be a good thing. __ R-help@r-project.org mailing list -- To UN

Re: [R] Is there a sexy way ...?

2024-09-28 Thread avi.e.gross
of R users having any special name like “R-thritic” and that may be a good thing. From: CALUM POLWART Sent: Saturday, September 28, 2024 5:27 AM To: avi.e.gr...@gmail.com Cc: Lennart Kasserra ; Rolf Turner ; r-help@r-project.org Subject: Re: [R] Is there a sexy way ...? Avi I fear

Re: [R] Is there a sexy way ...?

2024-09-28 Thread CALUM POLWART
problem space as quite vast. > > -Original Message- > From: R-help On Behalf Of Lennart Kasserra > Sent: Saturday, September 28, 2024 1:59 AM > To: Rolf Turner ; r-help@r-project.org; > lennart.kasse...@gmail.com > Subject: Re: [R] Is there a sexy way ...? > > Sorry

Re: [R] Is there a sexy way ...?

2024-09-27 Thread avi.e.gross
om Subject: Re: [R] Is there a sexy way ...? Sorry to append, but I just realised that of course ``` x |> pmap(c) |> reduce(c) |> unname() ``` also works and is a general solution in case your list has more than three elements. Here, we map in parallel over all elements o

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Lennart Kasserra
Sorry to append, but I just realised that of course ``` x |>   pmap(c) |>   reduce(c) |>   unname() ``` also works and is a general solution in case your list has more than three elements. Here, we map in parallel over all elements of the list, always combining the current set of elements in

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Lennart Kasserra
Hi Rolf, this topic is probably already saturated, but here is a tidyverse solution: ``` library(purrr) x <- list(   `1` = c(7, 13, 1, 4, 10),   `2` = c(2, 5,  14, 8, 11),   `3` = c(6, 9, 15, 12, 3) ) x |>   pmap(~ c(..1, ..2, ..3)) |>   reduce(c) #> [1]  7  2  6 13  5  9  1 14 15  4  8 12 1

Re: [R] Is there a sexy way ...?

2024-09-27 Thread avi.e.gross
0 11 12 c 13 14 15 16 17 18 d 19 20 21 22 23 24 -Original Message- From: Sorkin, John Sent: Saturday, September 28, 2024 12:01 AM To: avi.e.gr...@gmail.com; 'Rolf Turner' ; r-help@r-project.org Subject: Re: [R] Is there a sexy way ...? "Sexy code&q

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Sorkin, John
: 'Rolf Turner'; r-help@r-project.org Subject: Re: [R] Is there a sexy way ...? Rold, We need to be clear on what makes an answer sexy! LOL! I decided it was sexy to do it in a way that nobody (normal) would and had not suggested yet. Here is an original version I will explain in a

Re: [R] Is there a sexy way ...?

2024-09-27 Thread avi.e.gross
ual items # Python, not R. [num for elem in [(first, second, third) for first, second, third in zip(*x)] for num in elem] [7, 2, 6, 13, 5, 9, 1, 14, 15, 4, 8, 12, 10, 11, 3] For any interested, you can combine python and R in the same program back and forth on the same data inside what is st

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Bert Gunter
This post obviously beats a fossilized horse, so feel free to ignore. So here's my problem with my "solution" to Rolf's query as well as several others: it assumes that one knows the details of how matrices are stored as vectors with a 'dim' attribute. Although this might be considered elementary

Re: [R] Is there a sexy way ...?

2024-09-27 Thread avi.e.gross
, 6, 13, 5, 9, 1, 14, 15, 4, 8, 12, 10, 11, 3] ---END OUTPUT --- I am not saying to use python, just showing other ways people find comfortable. But choosing the right data structure can make things easy, or at least easier. -Original Message- From: R-help On Behalf Of Rolf Turner Sent: Th

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Martin Maechler
> Chris Evans via R-help > on Fri, 27 Sep 2024 12:20:47 +0200 writes: > Oh glorious!  Thanks Duncan. > Fortune cookie nomination! I don't disagree with the nomination -- thank you, Duncan! However, please note that I'm sure Rolf's was challenged / question was ment to work

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Chris Evans via R-help
Oh glorious!  Thanks Duncan. Fortune cookie nomination! On 27/09/2024 11:13, Duncan Murdoch wrote: On 2024-09-26 11:55 p.m., Rolf Turner wrote: I have (toy example): x <- list(`1` = c(7, 13, 1, 4, 10),    `2` = c(2, 5,  14, 8, 11),    `3` = c(6, 9, 15, 12, 3)) and f <- facto

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Duncan Murdoch
On 2024-09-26 11:55 p.m., Rolf Turner wrote: I have (toy example): x <- list(`1` = c(7, 13, 1, 4, 10), `2` = c(2, 5, 14, 8, 11), `3` = c(6, 9, 15, 12, 3)) and f <- factor(rep(1:3,5)) I want to create a vector v of length 15 such that the entries of v, corresponding to l

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Mark Leeds
Rolf can tell us for sure but I thought the goal was to use v ? Maybe not ? Either way, I think Bert wins for shortest and Kimmo wins for longest. IMHO, elegance is in the eye of the beholder. On Fri, Sep 27, 2024 at 4:35 AM Stephen Berman via R-help < r-help@r-project.org> wrote: > Yet ano

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Stephen Berman via R-help
Yet another way (not as sexy as Deepayan's): as.vector(t(sapply(x, c))) Steve Berman On Fri, 27 Sep 2024 10:45:06 +0300 Eric Berger wrote: > v <- as.numeric(matrix(unlist(x),ncol=5,byrow=TRUE)) > v > [1] 7 2 6 13 5 9 1 14 15 4 8 12 10 11 3 > > On Fri, Sep 27, 2024 at 8:33 AM Deepayan

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Kimmo Elo
Dear Rolf, dear all, this was an inspiring challenge :-) This seems to do the task... --- snip --- x <- list(`1` = c(7, 13, 1, 4, 10), `2` = c(2, 5, 14, 8, 11), `3` = c(6, 9, 15, 12, 3)) f <- factor(rep(1:3,5)) v <- as.vector(unlist(x)[ paste(rep(levels(f), length(x[[1]]

Re: [R] Is there a sexy way ...?

2024-09-27 Thread Eric Berger
v <- as.numeric(matrix(unlist(x),ncol=5,byrow=TRUE)) v [1] 7 2 6 13 5 9 1 14 15 4 8 12 10 11 3 On Fri, Sep 27, 2024 at 8:33 AM Deepayan Sarkar wrote: > > > unsplit(x, f) > [1] 7 2 6 13 5 9 1 14 15 4 8 12 10 11 3 > > Is more general (works if the subgroups are imbalanced), and

Re: [R] Is there a sexy way ...?

2024-09-26 Thread Deepayan Sarkar
> unsplit(x, f) [1] 7 2 6 13 5 9 1 14 15 4 8 12 10 11 3 Is more general (works if the subgroups are imbalanced), and hopefully more sexy as well :-) Best, -Deepayan On Fri, 27 Sept 2024 at 10:11, Bert Gunter wrote: > ... And, in fact, I just realized that > > c(do.call(rbind, x)) >

Re: [R] Is there a sexy way ...?

2024-09-26 Thread Bert Gunter
... And, in fact, I just realized that c(do.call(rbind, x)) is even better. -- Bert On Thu, Sep 26, 2024 at 9:26 PM Bert Gunter wrote: > Sorry, hit send by accident. > The 2-line version is: > > x <- do.call(rbind, x) > dim(x) <- NULL > > Cheers, > Bert > > On Thu, Sep 26, 2024 at 9:23 PM Be

Re: [R] Is there a sexy way ...?

2024-09-26 Thread Bert Gunter
Sorry, hit send by accident. The 2-line version is: x <- do.call(rbind, x) dim(x) <- NULL Cheers, Bert On Thu, Sep 26, 2024 at 9:23 PM Bert Gunter wrote: > How about: > as.vector(do.call(rbind,x)) > > Cheers, > Bert > > > > > However, I much prefer a 2 line version: > > On Thu, Sep 26, 2024 at

Re: [R] Is there a sexy way ...?

2024-09-26 Thread Bert Gunter
How about: as.vector(do.call(rbind,x)) Cheers, Bert However, I much prefer a 2 line version: On Thu, Sep 26, 2024 at 8:56 PM Rolf Turner wrote: > > I have (toy example): > > x <- list(`1` = c(7, 13, 1, 4, 10), > `2` = c(2, 5, 14, 8, 11), > `3` = c(6, 9, 15, 12, 3)) > an

Re: [R] Is there a sexy way ...?

2024-09-26 Thread avi.e.gross
4 8 12 10 11 3 -Original Message- From: R-help On Behalf Of Rolf Turner Sent: Thursday, September 26, 2024 11:56 PM To: r-help@r-project.org Subject: [R] Is there a sexy way ...? I have (toy example): x <- list(`1` = c(7, 13, 1, 4, 10), `2` = c(2, 5, 14, 8, 11),

[R] Is there a sexy way ...?

2024-09-26 Thread Rolf Turner
I have (toy example): x <- list(`1` = c(7, 13, 1, 4, 10), `2` = c(2, 5, 14, 8, 11), `3` = c(6, 9, 15, 12, 3)) and f <- factor(rep(1:3,5)) I want to create a vector v of length 15 such that the entries of v, corresponding to level l of f are the entries of x[[l]]. I.e. I