Giorgio Garziano
2015-Oct-03 15:17 UTC
[R] denstrip package: densregion when density is not provided
>From the "densregion" help page I can read that:z is a matrix of densities on the grid defined by x and y, with rows corresponding to elements of x and columns corresponding to elements of y. So in your scenario z must be a 3 rows x 100 columns matrix, if you like to take advantage of densregion(). z cannot be a data frame, otherwise you get the error you mentioned. Run this to verify. require(denstrip) set.seed(11) x <- 0:2 nx <- length(x) y <- seq(0, 1, length=100) ny <- length(y) # z is a matrix z <- matrix(nrow=nx, ncol=ny) for(i in 1:nx) z[i,] <- dnorm(y, 0, 1) dim(z) class(z) # works plot(x, type="n", ylim=c(-1, 1)) densregion(x, y, z, colmax="darkgreen") # does not work z.df <- data.frame(z) densregion(x, y, z.df, colmax="darkgreen") Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) : undefined columns selected -- GG [[alternative HTML version deleted]]