R Under development (unstable) (2024-11-06 r87293 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # https://github.com/r-spatial/stars/issues/295 > suppressPackageStartupMessages(library(stars)) > raw <- read_stars(system.file("nc/bcsd_obs_1999.nc", package = "stars")) pr, tas, > foo <- function(x, idx) stats::lowess(idx, x)$y > > timeline <- st_get_dimension_values(raw, "time") > smooth = st_apply(raw, + MARGIN = c("x", "y"), + FUN = foo, + idx = st_get_dimension_values(raw, "time") + ) > > st_set_dimensions(smooth, + which = "foo", + values = st_get_dimension_values(raw, "time"), + names = "time" + ) stars object with 3 dimensions and 2 attributes attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. NA's pr 16.133519 70.371665 84.55774 87.72969 101.94830 278.6427 7116 tas -2.354958 9.632157 15.32671 14.61650 19.99331 24.7976 7116 dimension(s): from to offset delta refsys values x/y time 1 12 NA NA POSIXct 1999-01-31,...,1999-12-31 x 1 81 -85 0.125 NA NULL [x] y 1 33 37.12 -0.125 NA NULL [y] > > raw %>% + st_apply(MARGIN = c("x", "y"), FUN = foo, idx = timeline) %>% + st_set_dimensions("foo", st_dimensions(raw)["time"]) stars object with 3 dimensions and 2 attributes attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. NA's pr 16.133519 70.371665 84.55774 87.72969 101.94830 278.6427 7116 tas -2.354958 9.632157 15.32671 14.61650 19.99331 24.7976 7116 dimension(s): from to offset delta refsys values x/y time 1 12 NA NA POSIXct 1999-01-31,...,1999-12-31 x 1 81 -85 0.125 NA NULL [x] y 1 33 37.12 -0.125 NA NULL [y] > > proc.time() user system elapsed 2.00 0.31 2.26