Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下变量:
i="QW"
我想使用 i 定义以下 vectore :
> c(QW=3) QW 3
但是,当我使用
> c(i=3) i 3
如您所见,它不起作用。那么如何告诉 c() 使用i的值而不是使用字符“i”来命名列?
您可以使用setNames:
setNames
setNames(3, i) # QW # 3
一种方法是使用names
names
i <- "QW" dat <- c(3) names(dat) <- i
给出QW3 值的一种方法是
QW
i <- "QW" eval(call("<-", as.name(i), 3) ) QW