用于R中的管道循环 [英] use for loop with pipes in R
本文介绍了用于R中的管道循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用magrittr库在R中使用管道.我需要在两个管道之间使用for循环,我该怎么做
I am using pipes in R using magrittr library. I need to use for loop in between of the pipes, how would i do that
tmrank.ft <- regulartable(
data = tm.rank.out) %>%
theme_booktabs() %>%
autofit() %>%
merge_v(j=missing_species) %>%
align(align = 'center') %>%
align(align = 'center', part = 'header') %>%
bold(part = 'header') %>%
height(height = 1, part = 'header') %>%
fontsize(size = 14, part = 'all') %>%
width(j=1, width = 1.0 ) %>%
width(j=2:ncol(tm.rank.out), width = 2.5) %>%
{
for (ii in 2:length(species))
{
group_result <- group_vector(tm.rank.out.temp, grp.type, species[ii])
for (jj in 1:length(group_result))
{
text_color <- grp.clr[[unique(grp.type[,grp][jj])]]
color(i = group_result[[jj]], j = ~ species[ii], color = text_color)
}
}
}
它把我扔了
inherits(x,"flextable")中的错误: 参数"x"丢失,没有默认值
Error in inherits(x, "flextable") : argument "x" is missing, with no default
推荐答案
只需预定义函数:
foo <- function(x){
for (ii in 2:length(species))
{
group_result <- group_vector(tm.rank.out.temp, grp.type, species[ii])
for (jj in 1:length(group_result))
{
text_color <- grp.clr[[unique(grp.type[,grp][jj])]]
color(i = group_result[[jj]], j = ~ species[ii], color = text_color)
}
}
}
tmrank.ft <- regulartable(
data = tm.rank.out) %>%
theme_booktabs() %>%
autofit() %>%
merge_v(j=missing_species) %>%
align(align = 'center') %>%
align(align = 'center', part = 'header') %>%
bold(part = 'header') %>%
height(height = 1, part = 'header') %>%
fontsize(size = 14, part = 'all') %>%
width(j=1, width = 1.0 ) %>%
width(j=2:ncol(tm.rank.out), width = 2.5) %>%
foo()
这篇关于用于R中的管道循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文