I have a regression table in latex that is the result of output from applying the stargazer package on my regression results in R. I am wondering how to transpose the table such that the columns switch place with rows. In other words, I want the Lags to be where the variables are and vice versa.
Moreover, I am wondering how to reduce the space between the first and second columns as well as how to add a vertical line between columns. I've tried adding | in between, but sometimes this doesn't cover well and leaves in some space in between the top and bottom hline.
\usepackage{dcolumn}
\begin{table}[!htbp] \centering
\caption{Regression results}
\label{}
\setlength{\tabcolsep}{0pt}
\begin{tabular}{lD{.}{.}{-2} D{.}{.}{-2} D{.}{.}{-2} D{.}{.}{-2} D{.}{.}{-2} D{.}{.}{-2}}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& \multicolumn{6}{c}{Characteristics} \\
\cline{2-7}
\\
Lags: & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{5} & \multicolumn{1}{c}{6} \\
\hline \\[-1.8ex]
Variable 1 & -1.14^{***} & 0.04 & -1.73^{***} & -0.24 & -0.59 & -1.64^{***} \\
Variable 2 & 0.16 & -0.25 & 0.12 & -0.12 & 0.14{**} & 0.04 \\
Variable 3 & 0.46^{*} & -0.61 & 0.17 & -0.98^{***} & -0.32 & -0.09\\
Variable 4 & -0.02 & -0.005 & -0.03^{***} & -0.32 & -0.11 & 0.015 \\
\hline \\[-1.8ex]
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{6}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}

\multicolumn{18}in a table that has only 7 columns. To get rid of the error message and simultaneously solve issue 2, you can use\multicolumn{7}{l}{\textit{Note:} $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}. – leandriis May 19 '20 at 17:31\textit{Note:} & \multicolumn{7}will still give you an error message since this adds up to 8 columns. Either place the "Note" inside the multicolumn as well or use\multicolumn{6}– leandriis May 19 '20 at 17:36\\[-1.8ex]\hline \hline \\[-1.8ex]for the horizontal lines above the table. Insetad of that, I would use\toprulefrom thebooktabspackage. (However, thebooktabslines are incompatible with vertical lines, thus, I would not use a vertical line at all.) – leandriis May 19 '20 at 17:38xmatrix/data.frame of results withy <- t(x)and then exportyto a latex table with stargazer, or xtable, or kable. If you add to the question a R code making a matrix/dataframe and the code that you use to produce the latex table, we could help from this point, ideally without having to touch up the R output. – Fran May 21 '20 at 04:28