rfootnotes

Add R markdown footnote within table code


I am struggling with how to use [^1] footnotes within r chunks for my r markdown document. I have a table that I need to add some footnotes to but I can't figure out how to add them. I want the 1 subscript to appear beside the end of the word "Pay" I have attempted the following code when trying to add a footnote to the first entry in the 'key_points' column:


mainPoints <- data.frame(key_points = c(paste0("Median Pay", [^1], "has increased by ", YearChangePct, "%"),
                                        paste0("Top decile Pay: £", TopDecile,"\nBottom decile Pay: £", BottomDecile),
                                        paste0(PayRisePct, "% of BLUB staff received a pay\nincrease between ", currentyear - 1, " and ", currentyear),
                                        paste0("Gender Pay gap is ", GenderPayGap, "%")),
                         Commentary = c(paste0("The average (median full-time equivalent) pay of BLUB staff is £", CurrentYearMedian, " which is an increase of ", YearChangePct, "% on the equivalent figure for ", currentyear -1, ". The overall pay award for the BLUB for ", currentyear -1, " was 1%."),
                                        paste0("Pay of £", BottomDecile, " would put someone in the bottom 10% of BLUB staff, whereas pay of £", TopDecile, " would put someone in the top 10% of BLUB staff."),
                                        paste0("The extent of the increase varied between grades: ", AApct, "% of AA staff received a pay increase between 0.1% and 1.9%. ", IND2pct,"% of Industrial 2 staff received a pay increase between 4.0% and 5.9%."),
                                        paste0("There continues to be a gap between male and female pay in the BLUB – the median pay for females is ", GenderPayGap, "% lower than the median pay for males.")))

names(mainPoints) <- c("Key Points", "Commentary")

Solution

  • The caret must be before the bracket: ^[footnote content]
    You can include it inside you string: "Median Pay^[footnote content] has increased by "
    Passing your table through knitr::kable(mainPoints) will do the job:

    ---
    output: html_document
    ---
    
    Footnote in cell:
    
    ```{r, echo = F}
    mainPoints <- data.frame(Key_points = c("Median pay^[footnote content]", "Top decile"),
                             Commentary = c("Comment 1", "Comment 2"))
    
    knitr::kable(mainPoints)
    ```
    

    enter image description here