如何在R中获取列表索引的向量
How to get vector of index of list in R
我尝试获取列表的索引,例如set_of_paragraphs("Two sample t-test",list_new2[[1]], list_new2[[2]],list_new2[[3]],list_new2[[4]])
...等等。
library(ReporteRs)
list_new <- c("Text1","Text2","String","Another Text")
my_text <- letters[1:length(list_new)]
list_new1 <- paste0(my_text, list_new,sep="")
list_new2 <- lapply(list_new1, function(i) pot(substr(i,1,1),textProperties(color="blue",vertical.align="superscript"))+substring(i,2))
函数set_of_paragraphs
仅在我列出列表中的所有索引时才起作用
set_of_paragraphs("Two sample t-test",list_new2[[1]], list_new2[[2]],list_new2[[3]],list_new2[[4]])
我尝试这样做,set_of_paragraphs
给我错误
Error in set_of_paragraphs(l, list_new2) :
set_of_paragraphs can only contains pot objects.
l <- list("Two sample t-test")
set_of_paragraphs(l,list_new2)
所以对我来说最好的方法是像这段代码一样列出它们set_of_paragraphs("Two sample t-test",list_new2[[1]], list_new2[[2]],list_new2[[3]],list_new2[[4]])
,但问题是,我有这么多,有什么方法可以写循环或申请访问索引。
如果您想调用带有参数列表的函数,您可以使用 do.call
。尝试
l <- list("Two sample t-test")
do.call("set_of_paragraphs" c(l, list_new2))
这相当于
set_of_paragraphs(l[[1], list_new2[[1]], list_new2[[2]], list_new2[[3]], ...)
(我无法测试,因为那个包似乎需要 Java 我没有安装。)基本上你把所有的参数都放在一个大列表中(这里我使用 c()
加入两个列表)。
我尝试获取列表的索引,例如set_of_paragraphs("Two sample t-test",list_new2[[1]], list_new2[[2]],list_new2[[3]],list_new2[[4]])
...等等。
library(ReporteRs)
list_new <- c("Text1","Text2","String","Another Text")
my_text <- letters[1:length(list_new)]
list_new1 <- paste0(my_text, list_new,sep="")
list_new2 <- lapply(list_new1, function(i) pot(substr(i,1,1),textProperties(color="blue",vertical.align="superscript"))+substring(i,2))
函数set_of_paragraphs
仅在我列出列表中的所有索引时才起作用
set_of_paragraphs("Two sample t-test",list_new2[[1]], list_new2[[2]],list_new2[[3]],list_new2[[4]])
我尝试这样做,set_of_paragraphs
给我错误
Error in set_of_paragraphs(l, list_new2) :
set_of_paragraphs can only contains pot objects.
l <- list("Two sample t-test")
set_of_paragraphs(l,list_new2)
所以对我来说最好的方法是像这段代码一样列出它们set_of_paragraphs("Two sample t-test",list_new2[[1]], list_new2[[2]],list_new2[[3]],list_new2[[4]])
,但问题是,我有这么多,有什么方法可以写循环或申请访问索引。
如果您想调用带有参数列表的函数,您可以使用 do.call
。尝试
l <- list("Two sample t-test")
do.call("set_of_paragraphs" c(l, list_new2))
这相当于
set_of_paragraphs(l[[1], list_new2[[1]], list_new2[[2]], list_new2[[3]], ...)
(我无法测试,因为那个包似乎需要 Java 我没有安装。)基本上你把所有的参数都放在一个大列表中(这里我使用 c()
加入两个列表)。