gpt4 book ai didi

r - 在R中创建一个名为 "paste"的变量?

转载 作者:行者123 更新时间:2023-12-03 05:15:25 26 4
gpt4 key购买 nike

见下文:

paste("perf.a", "1", sep="")
# [1] "perf.a1"

如果我想给 perf.a1 赋值怎么办?

我尝试了as.nameas.symbol等,但没有效果:

as.name(paste("perf.a", "1", sep="")) = 5
# Error in as.name(paste("perf.a", "1", sep = "")) = 5 :
# target of assignment expands to non-language object
as.symbol(paste("perf.a", "1", sep="")) = 5
# Error in as.symbol(paste("perf.a", "1", sep = "")) = 5 :
# target of assignment expands to non-language object
noquote(paste("perf.a", "1", sep="")) = 5
# Error in noquote(paste("perf.a", "1", sep = "")) = 5 :
# target of assignment expands to non-language object

最佳答案

您可以使用assign ( doc ) 来更改 perf.a1 的值:

> assign(paste("perf.a", "1", sep=""),5)
> perf.a1
[1] 5

关于r - 在R中创建一个名为 "paste"的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5510966/

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