I see a book coming:
"666 ways to do the same thing in R ranked by sexiness."
Kidding aside, if you look under the covers of some of the functions we are
using, we may find we are taking steps back as some of them use others and
perhaps more functionality than we need.
But for a new rea
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
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
You are, of course, correct, John. But in a strange way, many people end up
finding their wife or husband not so sexy after many years and find others
now seem to be.
R is not about sex and it was not the ideal choice of words.
I think what was wanted was something brief rather than taking many l
"Sexy code" may get a job done and demonstrate the code's knowledge of a
programming language, but it often does this at the expense of clear, easy to
document (i.e. annotate what the code does), easy to read, and easy to
understand code. I fear that this is what this thread has developed "sexy"
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 minute. Or, maybe best a bit
before. Hee is the unformatted result whicvh is a tad hard to re
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
Rolf,
I, and many others have come up with an assortment of solutions that seem to
work, often by ignoring whatever you intend by mentioning f as a factor.
But consider a dumb question. Why are you starting with a list of vectors,
with odd pseudo-numeric names?
Many of the solutions started by c
> 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
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
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
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
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
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]]
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
15 matches
Mail list logo