I want to do something like the following in R:
a <- list(
x = 2 + 7,
y = x + 8
)
It appears that this is not possible, though, or at least not in this way. Is there any way to use the value of x
in defining y
? I know I could define two objects independently, x
and y
, then do list(x, y)
, but I'd rather skip creating a lot of extra objects in my workspace.
With dplyr::lst
, we can do this
library(dplyr)
lst(x = 2 + 7, y = x + 8)
-output
$x
[1] 9
$y
[1] 17
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.