1

I am trying to apply adf.test to all columns of a dataframe. Some columns have NA values. I would like to store the output in a vector/list/dataframe.

H<-data.frame(replicate(10,sample(0:20,10,rep=TRUE))) 
H[c(2,3,7,9),9]<-NA
H[c(1,4,8),2]<-NA
H[c(1,2,3,4,8),4]<-NA

I get errors as below

oi<-adf.test(H,alternative="stationary")
Error in adf.test(H, alternative = "stationary") : 
  x is not a vector or univariate time series

lapply(na.omit(H),adf.test)
Error in res.sum$coefficients[2, 1] : subscript out of bounds

Package: tseries

Help is appreciated

1
  • akrun, i'm using tseries for adf.test
    – oivemaria
    Feb 21, 2015 at 4:49

1 Answer 1

1

You could try

lapply(H, function(x) adf.test(x[!is.na(x)], 
           alternative='stationary', k=0)) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.