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 <bgunter.4567 at gmail.com>
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 8:56?PM Rolf Turner <rolfturner at
posteo.net> 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.
>>
>> Can anyone point me in the right direction? Thanks.
>>
>> cheers,
>>
>> Rolf Turner
>>
>> --
>> Honorary Research Fellow
>> Department of Statistics
>> University of Auckland
>> Stats. Dep't. (secretaries) phone:
>> +64-9-373-7599 ext. 89622
>> Home phone: +64-9-480-4619
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> https://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
[[alternative HTML version deleted]]