问题
I am using the Dow Jones Dataset and I am trying to test skewness. So far this is the code:
library(tseries)
library(zoo)
library(reshape2)
library(fBasics)
dow = read.table('dow_jones_index.data', header=T, sep=',')
# create time series
dow <- read.table('dow_jones_index.data', header=T, sep=',', stringsAsFactors = FALSE)
# delete $ symbol and coerce to numeric
dow$close <- as.numeric(sub("\\$", "",dow$close))
tmp <- dcast(dow, date~stock, value.var = "close")
#tmp[,-1] means it's removing the first column (date) of tmp
dowts <- as.zoo(tmp[,-1], as.Date(tmp$date, format = "%m/%d/%Y"))
#compute simple returns ret = (p_t-p_(t-1))/p_(t-1)
dowgrowth = (dowts-lag(dowts, k=-1))/lag(dowts, k=-1)
#Skewness test
skew_test = skewness(dowgrowth)/sqrt(6/length(dowgrowth))
Everything runs fine except the skew_test line which gives me an error of:
Error: NCOL(x) == 1 is not TRUE
Not sure where to go from here. Thanks.
来源:https://stackoverflow.com/questions/35113719/testing-skewness-in-time-series-data-using-r-but-getting-error-ncolx-1-is