How to convert raster to 1D vector and export it

I have raster files, where each raster file represents one month of data. For example, rast1 represents values at each grid cell in January, rast2 represents values at each grid cell in February, and so on. At each grid cell, I want to combine the values from each month, format it as a 1D vector, and then export it as a txt file.

My dataset is presented as the figure below, but my actual raster files are just values, like this one.

V1 V2 V3 V4 V5
1 28.91 24.06 28.92 -99.00 -99.00
2 35.78 26.79 23.25 28.37 30.61
3 43.88 36.08 26.76 28.39 28.95
4 52.78 42.25 35.51 35.05 35.06
5 60.44 55.77 44.48 42.82 47.24

I want to combine all months of data for each grid cell, export it with the file name: value_latitude_longitude.txt, and the content in each txt file is like the example:


How to do this? Especially for so many months and so many grid cells. Thanks for your help. Also, when exporting the values, I do not want to include the cells with NAs. Thanks for your help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.