使用knitr和Latex問題

使用knitr和Latex問題

所以我目前正在使用 R 中的 micEconCES 套件進行 CES 函數估計。這是 R 中的簡化版本。

在此輸入影像描述

這是我在 R 中使用的程式碼。

\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
@

相關內容