Several functions (for example KernSmooth::bkde2D()
)
return a surface as a list "xyz" composed of three elements:
vector of ordinates in the x dimension,
vector of ordinates in the y dimension and
a matrix with the values of the surface in x and y.
This function transforms a list "xyz" into a data frame.
Note
xyz
could be a list like x,y,z1,z2,z3
.
If so, zcol
should be equal
to c("z1","z2","z3")
or c(3,4,5)
.
Examples
x <- matrix(c(2, 4, 6, 8, 10, 2, 4, 6, 8, 10), ncol = 2)
op <- KernSmooth::bkde2D(x, bandwidth = 1)
str(op)
#> List of 3
#> $ x1 : num [1:51] 0.5 0.72 0.94 1.16 1.38 1.6 1.82 2.04 2.26 2.48 ...
#> $ x2 : num [1:51] 0.5 0.72 0.94 1.16 1.38 1.6 1.82 2.04 2.26 2.48 ...
#> $ fhat: num [1:51, 1:51] 0.00339 0.00459 0.00593 0.00729 0.00855 ...
op.df <- xyz2dataframe(op)
str(op.df)
#> 'data.frame': 2601 obs. of 3 variables:
#> $ x1 : num 0.5 0.72 0.94 1.16 1.38 1.6 1.82 2.04 2.26 2.48 ...
#> $ x2 : num 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
#> $ fhat: num 0.00339 0.00459 0.00593 0.00729 0.00855 ...