I want to perform a Jarque-Bera Test with the tseries
package on a data.frame
with about 200 columns but it doesn't work with NA values.
My data.frame
looks like this:
d1 <- structure(list(Time=structure(17942:17947, class="Date"),
x1=c(NA, NA, 17L, 29L, 27L, 10L),
x2=c(30L, 19L, 22L, 20L, 11L, 24L),
x3=c(NA, 23L, 22L, 27L, 21L, 26L),
x4=c(30L, 28L, 23L, 24L, 10L, 17L),
x5=c(12L, 18L, 17L, 16L, 30L, 26L)),
row.names=c(NA, 6L), class="data.frame")
Output:
Time x1 x2 x3 x4 x5
1 2019-02-15 NA 30 NA 30 12
2 2019-02-16 NA 19 23 28 18
3 2019-02-17 17 22 22 23 17
4 2019-02-18 29 20 27 24 16
5 2019-02-19 27 11 21 10 30
6 2019-02-20 10 24 26 17 26
I tried:
library(tseries)
JB <- lapply(2:6, function(i) jarque.bera.test(d1[,i]))
but this gives me following error message:
Error in jarque.bera.test(d1[, i]) : NAs in x
Also JB <- lapply(2:6, function(i) jarque.bera.test(d1[,i], na.rm=TRUE))
did not work.
The NA's are only at the beginning of the time series. I'm therefore looking for way to ignore the NA's at the beginning of the time series.
Thank you!