所以我目前正在使用 R 中的 micEconCES 包进行 CES 函数估计。我想将估计的输出合并到我的 latex 文件中,但我似乎无法让它工作。这是 R 中的简化版本。我希望它看起来像这样
这是我在 R 中使用的代码。如果我在 R 中一步一步输入代码,那么我会得到想要的输出,但如果将其合并到 Rnw 文件中,我会收到错误消息。
\documentclass{article}
\begin{document}
#starting the R code
<<>>=
#reading in my data set from excel and changing a couple columns to
numeric
DATA_FOR_2<- read_excel("~/Documents/DATA FOR 2.xlsx", col_types =
c("text", "text", "text","text", "text", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric", "numeric", "numeric",
"numeric", "numeric"))
#cutting out some unneeded rows
mydata <- DATA_FOR_2[-c(46:62), ]
#using the micEconCES code to do the Kmenta approximation
cesKmenta <- cesEst( yName = "gddp", xNames = c( "capiital", "labora"
), data = mydata, method = "Kmenta", vrs = TRUE )
#calling summary stats
summary(cesKmenta)
#plotting the results
compPlot ( mydata$gddp, fitted( cesKmenta ), xlab = "actual values",
ylab = "fitted values" )
@
\end{document}
但是当我将此代码编译为 PDF 时,我收到错误消息:
DATA_FOR_2<- read_excel("~/Documents/DATA FOR 2.xlsx", col_types = c("text", "text", "text","text", "text", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"))## Error in eval(expr, envir, enclos): konnte Funktion "readexcel"nicht finden
mydata <- DATA_FOR_2[-c(46:62), ]## Error in eval(expr, envir, enclos): Objekt 'DATAFOR2' nicht gefunden
cesKmenta <- cesEst( yName = "gddp", xNames = c( "capiital", "labora" ), data = mydata, method = "Kmenta", vrs = TRUE )## Error in eval(expr, envir, enclos): konnte Funktion "cesEst" nicht finden
summary(cesKmenta)## Error in summary(cesKmenta): Objekt 'cesKmenta' nicht gefunden
compPlot ( mydata$gddp, fitted( cesKmenta ), xlab = "actual values",ylab = "fitted values" )## Error in eval(expr, envir, enclos): konnte Funktion "compPlot"nicht finden1
我究竟做错了什么?
答案1
你可能忘记加载函数库了read_excel
。第一行有一条明确的错误信息:
konnte Funktion "readexcel"nicht finden
您必须library(readxl)
在文档中添加(如果是软件包名称)。您可以在%starting the R code
加载文档所需的所有库后添加额外的代码块,并将其放在一个位置
<<Load library>>
library(readxl)
# Other packages
@