knitr 및 Latex 문제 사용

knitr 및 Latex 문제 사용

그래서 저는 현재 R의 micEconCES 패키지를 사용하여 CES 함수 추정을 수행하고 있습니다. 추정 결과를 라텍스 파일에 통합하고 싶지만 제대로 작동하지 않는 것 같습니다. 이것은 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
@

관련 정보