2017-02-28 5 views
1

リストのインデックスを取得しようとします。たとえば、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("Two sample t-test",list_new2[[1]], list_new2[[2]],list_new2[[3]],list_new2[[4]]) 

リスト内のインデックスをすべてリストする場合にのみ、私はこの方法を実行しようと働くset_of_paragraphs機能、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]])しかし、問題は、私は非常に多くを持っているループを書くか、またはアクセスインデックスに適用する方法があります。

答えて

2

パラメータのリストで関数を呼び出す場合は、do.callを使用できます。これは

set_of_paragraphs(l[[1], list_new2[[1]], list_new2[[2]], list_new2[[3]], ...) 

のと同じです

l <- list("Two sample t-test") 
do.call("set_of_paragraphs" c(l, list_new2)) 

を試してみてください(そのパッケージが、私がインストールされていないもののJavaを必要としているようですので、私はテストすることはできません。)基本的には一つの大きなリストにすべてのパラメータを置きます(私はc()を使って2つのリストを結合します)。

+0

ええ、それは完璧に動作します – BIN

関連する問題