spline - How can I smooth an array in R? -
I have a 2-D array in R, which represents the value data for the grid of rows and columns. It looks like:
[, 1] [, 2] [, 3] [, 4] [1,] 1 1 2 1 [2,] 1 5 6 3 [3,] 2 3 2 1 [4,] 1 1 1
I want to "smooth" these values at this proof-of-concept point, I use any popular smoothing ceremony OK to do I am currently trying to use the smooth.spline
function:
smooth.spline (x, y = null, w = null, df, spar = Null, cv = FALSE, all.knots = FALSE, nknots = NULL, keep.data = TRUE, df.offset = 0, penalty = 1, control.spar = list ())
< P> By ( When I run it, I get this error:
>Smooth. ) Error: At least four unique 'x' values are required
There are four or more unique values in each column in my array, so I I'm not sure I do not know how to properly format input data Can someone give me some pointers to talk like this? Examples of functions like Smoother
with single-dimension vectors I do not seem to be extrapolating in the 2-D world. I'm a new novice, so please do not hesitate to correct the misuse of the conditions here!
< Div class = "post-text" itemprop = "text">
1 -D In either the vertical or horizontal axis, use:
Apply (myarray, 1, smooth.spline)
or
2-D is not familiar with smoothing, but a quick experiment with the package of fields seemed to work. apply (myarray, 2, smooth.spline)
You have to install the package field
and its dependencies where myMatrix < / Code> The matrix you had above was ... (I recreate it):
# x, y and zm = c (1,1, 2,1,1,5, 6,3,2,3,2,1,1,1,1,1) myMatrix = matrix (m, 4,4, t) matrix [, 1] [, 2] [, 3] [, 4] [ 1,] 1 1 2 1 [2,] 1 5 6 3 [3,] 2 3 2 1 [4,] 1 1 1 Z = as.vector (myMatrix) XY = Data .frame (x = as.numeric ( Gl (4,1,16), y = as numeric (gl (4,4,16)) t = tps (xy, z) surface (t)
A beautiful conspiracy Built up
Comments
Post a Comment