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

Chris Evans chr|@ho|d @end|ng |rom p@yctc@org
Fri Sep 27 12:20:47 CEST 2024


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 <- 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
>
-- 
Chris Evans (he/him)
Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, 
University of Roehampton, London, UK.
CORE site: http://www.coresystemtrust.org.uk
Other work web site: https://www.psyctc.org/psyctc/
Personal site: https://www.psyctc.org/pelerinage2016/



More information about the R-help mailing list