Here is a workaround. At first, I put the years in a column and defined my own function for managing column names. This allows me to replace the name of the first column (in my code example here:) rotated[1]with something else.
library(xtable)
df <- data.frame(rows = 2013:2017, Fish=1:5, Bird=11:15)
print(xtable(df), include.rownames = F,
sanitize.colnames.function = function(x){
rotated <- paste("\\begin{sideways}", x, "\\end{sideways}")
return(c("Need coffee!", paste(rotated[-1], collapse="&")))}
)
\begin{table}[ht]
\centering
\begin{tabular}{rrr}
\hline
Need coffee! & \begin{sideways} Fish \end{sideways} &\begin{sideways} Bird \end{sideways} \\
\hline
2013 & 1 & 11 \\
2014 & 2 & 12 \\
2015 & 3 & 13 \\
2016 & 4 & 14 \\
2017 & 5 & 15 \\
\hline
\end{tabular}
\end{table}
Please note that you can still have your own names. The following works just as well:
df <- data.frame(Fish=1:5, Bird=11:15)
rownames(df) <- 2013:2017
print(xtable(tibble::rownames_to_column(df)), include.rownames = F,
sanitize.colnames.function = function(x){
rotated <- paste("\\begin{sideways}", x, "\\end{sideways}")
return(c("Need coffee!", paste(rotated[-1], collapse="&")))}
)