Skip to contents

Given smoother data \((x_i, y_i)\) and maybe weights \(w_i\), with multiple \(x_i\), use the unique x values, replacing the \(y\)'s by their (weighted) mean and updating the weights accordingly.

Usage

xy.unique.x(x, y, w, fun.mean = mean, ...)

Arguments

x,y

numeric vectors of same length. Alternatively, x can be a ‘xy’ like structure, see xy.coords.

w

numeric vector of non-negative weights – or missing which corresponds to all weights equal.

fun.mean

the mean function to use.

...

optional arguments all passed to unique.

Value

Numeric matrix with three columns, named x, y and w with unique x values and corresponding y and weights w.

Author

Martin Maechler, 8 Mar 1993.

See also

e.g., smooth.spline uses something like this internally.

Examples

## simple example:
x <- c(1,1,2,4,3,1)
y <- 1:6
rbind(x, y)
#>   [,1] [,2] [,3] [,4] [,5] [,6]
#> x    1    1    2    4    3    1
#> y    1    2    3    4    5    6
xy.unique.x(x, y)
#>   x y w
#> 1 1 3 3
#> 2 2 3 1
#> 3 4 4 1
#> 4 3 5 1
#   x y w
# 1 1 3 3
# 2 2 3 1
# 3 4 4 1
# 4 3 5 1
xy.unique.x(x, y, fromLast = TRUE)
#>   x y w
#> 1 2 3 1
#> 2 4 4 1
#> 3 3 5 1
#> 4 1 3 3