我正在lstlisting
将我的 R 代码包含到我的 LaTeX 中,但是后面的减号<
没有出现在编译的文件中。
\usepackage{listings}
\begin{document}
\begin{lstlisting} [language=R]
n<- c(10, 15, 20, 35)
w <- c(300, 500, 700,100)
i <- c(1, 1, 2, 2)
j <- c(1, 2, 1, 2)
beta <- c(1, 1)
for (iter in 1:20) {
alpha <- sqrt(tapply(w*n^2/beta[j], i, sum)/
tapply(w*beta[j], i, sum))
beta <- sqrt(tapply(w*n^2/alpha[i], j, sum)/
tapply(w*alpha[i], j, sum))}
alpha
1 2
11.41714 24.63072
beta
1 2
0.8229245 1.3470172
\end{lstlisting}
\end{document}
答案1
作为一个较长的评论,我在这里没有问题
\documentclass[a4paper]{memoir}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}
\begin{lstlisting}[language=R]
n<- c(10, 15, 20, 35)
w <- c(300, 500, 700,100)
i <- c(1, 1, 2, 2)
j <- c(1, 2, 1, 2)
beta <- c(1, 1)
for (iter in 1:20) {
alpha <- sqrt(tapply(wn^2/beta[j], i, sum)/ tapply(wbeta[j], i,sum))
beta <- sqrt(tapply(wn^2/alpha[i], j, sum)/ tapply(walpha[i],j,sum))
}
alpha 1 2 11.41714 24.63072 beta 1 2 0.8229245 1.3470172
\end{lstlisting}
\end{document}