[R] Is there a sexy way ...?
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Fri Sep 27 11:13:14 CEST 2024
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 level l of f are the entries of x[[l]]. I.e. I want
> v to equal
>
> c(7, 2, 6, 13, 5, 9, 1, 14, 15, 4, 8, 12, 10, 11, 3)
>
> I can create v "easily enough", using say, a for-loop. It seems to me,
> though, that there should be sexier (single command) way of achieving
> the desired result. However I cannot devise one.
>
Don't you find a for loop's naked display of intention to be sexy?
Duncan Murdoch
More information about the R-help
mailing list