Knitr/kable captions for each elements of list

Hello,
I am trying to convert my results table into PDF, but I am not be able to get the results as I want it to. As an example I am using the datasets iris. Here is the code in R Markdown:


---
title: "Untitled"
date: "06/11/2020"
output: pdf_document
---
```{r results = "asis", echo = FALSE}
      library(knitr)

      lapply(iris[-c(5)],function(x){
             result<-summary(lm(x~Species,data=iris))$coefficients
             ls <- list(table1=result,table2=result)
             
             for(x in seq_along(ls)){
               print(
                 kable(ls[[x]],caption=names(ls)[x])
               )
             }
        })

The results create a table with each of their caption, but it is not seperated with the name of the Species. Here is the pdf results:

test.pdf (73.6 KB)

Anyone could help me? Thank you!

What would the captions be if the code worked at desired?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

It would be look something like this, where every 2 table results would be seperated by the name of the species instead of having all the name of species at the end like in the PDF that I sent above.

Sorry for the late reply and Thank you!