您可以使用[<-
保留的属性:
named[] <- paste(named, description) first second "text 1 description 1" "text 2 description 2"
该解决方案具有使现有named
向量混乱的缺点。您可以通过两个步骤避免它:
x <- named x[] <- paste(named, description)
或做一个功能:
foo <- function(x, y) setNames(paste(x, y), names(x)) foo(named, description) first second "text 1 description 1" "text 2 description 2"