r - xyplot, Error in `[.xts`(y, id) : 'i' or 'j' out of range -
r - xyplot, Error in `[.xts`(y, id) : 'i' or 'j' out of range -
i trying scatter plot 2 variables, 1 of residuals lm()
call. xyplot()
function not scatter plot , returns error message
error in `[.xts`(y, id) : 'i' or 'j' out of range
the residuals xts variable , xyplot()
can in fact still plot residuals (just time plot, not scatter plot).
strangely, work around i've found far utilize as.xts()
on xts residuals, or utilize [ ,1]
indexing refer first column, though there 1 column begin with.
mwe below, looking explanation, in advance.
library('lattice') library('xts') = as.xts(ts(rnorm(20), start=c(1980,1), freq=4)) b = as.xts(ts(rnorm(20), start=c(1980,1), freq=4)) c = resid(lm(a~b)) str(c) # xts object xyplot(c~a) # not work: error in `[.xts`(y, id) : 'i' or 'j' out of range xyplot(c) # xyplot can plot fine xyplot(as.xts(c)~a) # works, if utilize as.xts() on xts object ? xyplot(c[ ,1]~a) # works, if refer 1st column of 1 column object ?
the problem because c
doesn't have dim
attribute, xts objects do, , how many xts functions expect xts objects have. set dim
attribute , everything's okay.
dim(c) <- c(length(c),1) xyplot(c~a)
r xts lattice
Comments
Post a Comment