[R] Is there a sexy way ...?
@vi@e@gross m@iii@g oii gm@ii@com
@vi@e@gross m@iii@g oii gm@ii@com
Fri Sep 27 06:20:57 CEST 2024
Rolf,
This works, albeit you may not be thrilled:
x <- list(`1` = c(7, 13, 1, 4, 10),
`2` = c(2, 5, 14, 8, 11),
`3` = c(6, 9, 15, 12, 3))
as.vector(rbind(x[[1]], x[[2]], x[[3]]))
-- output:
> as.vector(rbind(x[[1]], x[[2]], x[[3]]))
[1] 7 2 6 13 5 9 1 14 15 4 8 12 10 11 3
-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Rolf Turner
Sent: Thursday, September 26, 2024 11:56 PM
To: r-help using 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),
`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 using 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.
More information about the R-help
mailing list