R:值序列中的替换表达式序列

R: sequence of substituted expressions from sequence of values

我要制作

list(quote(10^2), quote(10^3), quote(10^4),
     quote(10^5), quote(10^6), quote(10^7))

来自

seq(2,7)

有没有比

更简单的方法呢?
mapply(function(n) substitute(10^x, list(x=as.double(n))), seq(2,7))

?我尝试了以下方法:

> substitute(10^x, list(x=seq(2,7)))
10^2:7

> mapply(substitute, 10^x, x=seq(2,7))
Error in mapply(substitute, 10^x, x = seq(2, 7)) : object 'x' not found

> mapply(function(n) substitute(10^n), seq(2,7))
list(10^dots[[1L]][[6L]], 10^dots[[1L]][[6L]], 10^dots[[1L]][[6L]], 
     10^dots[[1L]][[6L]], 10^dots[[1L]][[6L]], 10^dots[[1L]][[6L]])

你应该可以做到:

lapply(2:7, function(x) {
  substitute(10^x, list(x = x))
})

示例:

test <- lapply(2:7, function(x) {
  substitute(10^x, list(x = x))
})
str(test)
# List of 6
#  $ : language 10^2L
#  $ : language 10^3L
#  $ : language 10^4L
#  $ : language 10^5L
#  $ : language 10^6L
#  $ : language 10^7L

orig <- list(quote(10^2), quote(10^3), quote(10^4),
             quote(10^5), quote(10^6), quote(10^7))
str(orig)
# List of 6
#  $ : language 10^2
#  $ : language 10^3
#  $ : language 10^4
#  $ : language 10^5
#  $ : language 10^6
#  $ : language 10^7

唯一的区别是我的版本将值 2:7 视为整数(因此 "L")。

尝试 bquote:

lapply(as.numeric(2:7), function(x) bquote(10^.(x)))