我试图在一整天内处理一个意外的}
,但我无法让它发挥作用。当我运行此代码时,
read<-function(file){
+ df<-read.table(file=file,header=FALSE,sep = ",", na.strings = "NULL")
+ names(df)<-c("date","Open","High","Low","Close")
+ dl<-split(df,format(as.POSIXct(df$date),'%Y-%m-%d'))
+ lapply(dl,function(item){
+ xts(item[-1],order.by = as.POSIXct(item$date))
+ })
+ }
我收到此错误:
Error: unexpected '}' in:
"+ xts(item[-1],order.by = as.POSIXct(item$date))
+ }"
> + }
Error: unexpected '}' in "+ }"
答案 0 :(得分:2)
这是一个不应该破解的语法。它确实看起来像你在&#34; +&#34;来自其他地方的标记以及导致问题的标记。
read <- function(file) {
df <- read.table(file=file, header=FALSE, sep = ",", na.strings = "NULL")
names(df) <- c("date","Open","High","Low","Close")
dl <- split(df, format(as.POSIXct(df$date), '%Y-%m-%d'))
lapply(dl, function(item){ xts(item[-1], order.by = as.POSIXct(item$date))})
}