[R] denstrip package: densregion when density is not provided

Giorgio Garziano giorgio.garziano at ericsson.com
Sat Oct 3 17:17:54 CEST 2015


>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]]



More information about the R-help mailing list