全文code太多就不全部
library(readxl)
library(zoo)
dir.create("C:/Users/Microsoft/Desktop/ERF/assignment/international diversification works")#where we store the excel sheet
setwd("C:/Users/Microsoft/Desktop/ERF/assignment/international diversification works")
getwd()
datapath <- getwd()
file_in <- "Data_ERF_A2_2021-22.xlsx" #Filename
sheet_in <- "JP" #sheet name
JP <- read_excel(paste(datapath, file_in, sep = "/") , sheet = sheet_in,
col_types = c("date", rep("numeric", 12)),
col_names = TRUE)
industry_names<-colnames(JP)
industry_names<-industry_names[-c(1,13)]
months=JP[,1]
library(xts)
JP <- xts(JP[,-1], order.by = JP[[1]])#change as xts
library(PerformanceAnalytics)
library(kableExtra)
R <- Return.calculate(JP)#compute simple return
R <- na.omit(R)
stats <- table.Stats(R)#descriptive statistics
chart.CumReturns(R, wealth.index = TRUE,
main = paste0("Cumulative returns in ", sheet_in),
legend.loc = "topleft", col = rainbow(7))
感觉问题应该出在开头这部分,但是实在没搞懂这报错到底啥意思,明明前两天还能跑,今天重新开机就不能用了
报错内容如下
processing file: ERF2_22.rmd
Error in sub(re, "", x, perl = TRUE) : 输入的字符串18不是UTF-8
Calls: <Anonymous> ... partition_chunk -> endsWith -> trimws -> mysub -> sub
此外: Warning messages:
1: In readLines(con, warn = FALSE) : 输入链结'ERF2_22.rmd'内的输入不对
2: In xfun::read_utf8(input) :
The file ERF2_22.rmd is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 63, 65
停止执行
可能是编码的问题,都改成UTF-8编码之后再运行看看