gpt4 book ai didi

list - 从字符串创建列表

转载 作者:行者123 更新时间:2023-12-05 00:06:02 24 4
gpt4 key购买 nike

也许我的大脑今天不工作,但我无法弄清楚如何从 2 个字符串创建一个列表。

我目前有

scale_lab
[1] "Very Poor" "Poor" "Average" "Good" "Very Good"
[6] "Don't Know"


scale_rep
[1] "1" "2" "3" "4" "5" "9"

所以我想要做的是将两者合并到一个列表中,这样 1 = 非常差,2 = 差等等。

最佳答案

只需使用 names()分配它:

> scale_lab <- c("Very Poor", "Poor", "Average", "Good", 
+ "Very Good", "Don't Know")
> scale_rep <- c("1","2","3","4","5","9")
> names(scale_lab) <- scale_rep
> scale_lab
1 2 3 4 5 9
"Very Poor" "Poor" "Average" "Good" "Very Good" "Don't Know"
> scale_lab["9"]
9
"Don't Know"
>

关于list - 从字符串创建列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3852343/

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