gpt4 book ai didi

r - 构造一个命名列表而不必键入每个对象的名称两次

转载 作者:行者123 更新时间:2023-12-02 04:44:29 30 4
gpt4 key购买 nike

<分区>

在交互式使用中,我偶尔需要捆绑一大组对象一起在一个列表中。获取元素保留的列表他们原来的名字,我被迫写下类似的东西list(Object1=Object1, Object2=Object2, ..... , Object25=Object25)

是否有一些直接的方法可以将一组命名对象放入列表中,以便它们“保留”自己的名称,而不必为每个对象键入 nameXXX=nameXXX

cars <- mtcars[1:2,1:2]
vowels <- c("a","e","i","o","u")
consonants <- setdiff(letters, vowels)

## I'd like to get this result...
list(consonants=consonants, vowels=vowels, cars=cars)
## $consonants
## [1] "b" "c" "d" "f" "g" "h" "j" "k" "l" "m" "n" "p" "q" "r" "s" "t" "v" "w" "x"
## [20] "y" "z"
##
## $vowels
## [1] "a" "e" "i" "o" "u"
##
## $cars
## mpg cyl
## Mazda RX4 21 6
## Mazda RX4 Wag 21 6

## ... but by doing something more like
f(consonants, vowels, cars)

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com