Anka
Anka

Reputation: 1

using R raster to create a dataframe from nc file

I am using R to merge datasets of precipitation CPC Daily Precipitation .nc file and .rds data of a geo-referenced dataset on conflict (UCDP

I created a dataframe from the .nc file but the values of latitude and longitude do not seem right (some go up to 300 when 180 should be the max). Additionally, I am not able to include time in the data (so instead of 3 dimensions, lon, lat and time, I only have lon and lat and then the variable of precipitation).

Would you be able to advise me on creating dataframe from nc file?

library(raster)

precip <- raster("precip.day.ltm.1991-2020.nc",
                 level = 180,
                 varname = "precip")

proj4string(precip) <- CRS("+init=EPSG:4326")

precip.df2 <- raster::as.data.frame(precip, xy = TRUE)

precip.df2 %>% 
  sample_n(50) %>% 
  kableExtra::kable("html", 
                    row.names = FALSE, 
                    col.names = c("Longitude", "Latitude", "Precipitation"), 
                    align = "c", 
                    caption = "Test of data") %>% 
  kableExtra::column_spec(column = 1:3, width = "5cm", color = 1)

I assume there might be some problem with level = 180?

Upvotes: 0

Views: 30

Answers (0)

Related Questions