Apologies. I actually do not have a raster yet. I have created a rasterlayer but when I want to import by data (wide format and 49 variables), I get the following error.
Error in setValues(x, v) : values must be numeric, logical or factor In addition: Warning message: In v[] <- value : number of items to replace is not a multiple of replacement length Error in .local(x, i = i, j = j, ..., value) : cannot replace values on this raster (it is too large class : RasterLayer dimensions : 360, 720, 259200 (nrow, ncol, ncell) resolution : 0.5, 0.5 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs What I have is data for 49 years at grid cells (0.5°×0.5°) which I would like to write as a NetCDF file. Any help will be greatly appreciated. Thanks! Best, Milu On Sat, May 20, 2023 at 2:27 AM Alexander Ilich <ail...@usf.edu> wrote: > The WriteRaster should be able to do it ( > https://stackoverflow.com/questions/50026442/writing-r-raster-stack-to-netcdf). > Also, if practical, I'd recommend switching from the raster package to the > terra package which has replaced it and is written by the same author. The > syntax is almost identical so it's an easy transition. terra has a writeCDF > function which may work (https://rdrr.io/cran/terra/man/writeCDF.html). > > Best Regards, > Alex > > ------------------------------ > *From:* R-sig-Geo <r-sig-geo-boun...@r-project.org> on behalf of Miluji > Sb <miluj...@gmail.com> > *Sent:* Friday, May 19, 2023 7:19 PM > *To:* R-sig-geo mailing list <r-sig-geo@r-project.org> > *Subject:* [R-sig-Geo] Merge dataframe with NetCDF file > > [You don't often get email from miluj...@gmail.com. Learn why this is > important at https://aka.ms/LearnAboutSenderIdentification ] > > Dear all, > > I am struggling to convert a dataframe with 49 years of data for 259,200 > coordinates. How can I convert this dataset into a NetCDF file with the > following attributes; > > class : RasterBrick > dimensions : 360, 720, 259200, 10 (nrow, ncol, ncell, nlayers) > resolution : 0.5, 0.5 (x, y) > extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) > crs : +proj=longlat +datum=WGS84 +no_defs > year () : 1971, 1972, ..., 2019 > varname : fs > > Any help will be highly appreciated. > > Best, > > Milu > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > > https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=05%7C01%7Cailich%40usf.edu%7C0f7d47bd46514adffc8408db58bf9b44%7C741bf7dee2e546df8d6782607df9deaa%7C0%7C0%7C638201387342113041%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4%2FySAN%2BWpf4VPnWpJ464WBHBud2bZ0vVz4aV3k1pLHI%3D&reserved=0 > <https://stat.ethz.ch/mailman/listinfo/r-sig-geo> > [EXTERNAL EMAIL] DO NOT CLICK links or attachments unless you recognize > the sender and know the content is safe. > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo