I have a raster stack (my_stack) and I converted it into a stars object:

mystar <- st_as_stars(my_stack)

That results in:

stars object with 3 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
 Min.   :  0.0000  
 1st Qu.:  0.0000  
 Median :  0.0000  
 Mean   :  0.7897  
 3rd Qu.:  0.0000  
 Max.   :686.6100  
     from  to  offset delta                       refsys point               values    
x       1 904  104010  1000 +proj=tmerc +lat_0=0 +lon...    NA                 NULL [x]
y       1 773 4623806 -1000 +proj=tmerc +lat_0=0 +lon...    NA                 NULL [y]
band    1  67      NA    NA                           NA    NA layer.1,...,layer.67    

I also have a vector with Date objects. How could I add this vector as time dimension in mystar object?


This should work:

mystar = st_set_dimensions(mystar, 3, values = dates, names = "date")

where dates is the Date vector.

  • This will replace 3nd dimension with dates. Will not add new dimension.Right? – Leonidas Oct 21 at 14:35
  • 1
    Right. The st_set_dimensions function is used to modify the properties of existing dimensions. – Michael Dorman Oct 22 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.