Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何生成一个数组";“语言”-R中的对象?_Arrays_R_Types_Legend - Fatal编程技术网

Arrays 如何生成一个数组";“语言”-R中的对象?

Arrays 如何生成一个数组";“语言”-R中的对象?,arrays,r,types,legend,Arrays,R,Types,Legend,我想在数组中存储格式化的图例文本 normFactor= c(1e-1, 1e-2, 1e-3) legend_text[1] = bquote(mu ~ "=" ~ .(normFactor[1])) legend_text[2] = bquote(mu ~ "=" ~ .(normFactor[2])) legend_text[3] = bquote(mu ~ "=" ~ .(normFactor[3])) bquote输出的类型似乎是语言: str(bquote(mu ~ "=" ~

我想在数组中存储格式化的图例文本

normFactor= c(1e-1, 1e-2, 1e-3)

legend_text[1] = bquote(mu ~ "=" ~ .(normFactor[1]))
legend_text[2] = bquote(mu ~ "=" ~ .(normFactor[2]))
legend_text[3] = bquote(mu ~ "=" ~ .(normFactor[3]))
bquote输出的类型似乎是
语言

str(bquote(mu ~ "=" ~ .(normFactor[3])))
语言mu~“=”~0.001

所以我想我可以建立一个语言元素数组:

legend_text = language()

不幸的是,这不起作用,我想知道如何将这些元素存储在数组中,

语言不是原子数据类型,因此结果将是列表而不是向量。 动态键入是您的朋友:

legend_text<- c(
 bquote(mu ~ "=" ~ .(normFactor[1])),
 bquote(mu ~ "=" ~ .(normFactor[2])),
 bquote(mu ~ "=" ~ .(normFactor[3]))
)

legend\u text您可以将它们存储在列表中,或者更好地按如下方式创建它们:

lapply(seq_along(normFactor),
         function(i)bquote(mu ~ "=" ~ .(normFactor[i])))

[[1]]
mu ~ "=" ~ 0.1

[[2]]
mu ~ "=" ~ 0.01

[[3]]
mu ~ "=" ~ 0.001
bquote
创建语言对象实际上可以使用
as.list
as.call
在列表之间进行转换。因此,可以针对exmaple修改上述解决方案:

> ll <- lapply(seq_along(normFactor),
+        function(i)as.list(bquote(mu ~ "=" ~ .(normFactor[i]))))
> str(ll)
List of 3
 $ :List of 3
  ..$ : symbol ~
  ..$ : language mu ~ "="
  ..$ : num 0.1
 $ :List of 3
  ..$ : symbol ~
  ..$ : language mu ~ "="
  ..$ : num 0.01
 $ :List of 3
  ..$ : symbol ~
  ..$ : language mu ~ "="
  ..$ : num 0.001

如果使用
as.expression
对bquotes进行四舍五入,则此操作有效。见:
> lapply(ll,as.call)
[[1]]
mu ~ "=" ~ 0.1

[[2]]
mu ~ "=" ~ 0.01

[[3]]
mu ~ "=" ~ 0.001