I am trying to create a table in R Markdown, where values for each table row are generated inside of a for-loop inside of a code chunk.
Within the code chunk, I loop through a dataframe and calculate values for each output row. Each row has exactly the same format: first element is a text string, followed by 3 integers.
I've tried two different ends of the solution-spectrum for this problem...
- After each iteration of the loop, put the calculated values for one row into an R matrix. When the loop has completed, directly write out the matrix in one step with the cat command. However, the result of this method does not look like a table at all; all of the values appear in what appears to be a single "vector" or "list".
- In results='asis' mode, as each iteration of the loop executes, write out raw HTML table rows with specified widths. Here, I at least get the right format, but am unable to control the column-widths. TR WIDTH=80 produces a result that takes up only about 1/3 of the output area.
I suspect their is a better solution strategy, than tinkering with the two ideas above. Does anyone have any suggestions as to a best practice here?