I have three numeric vectors which describes:
- lat - lattitude
- long - longitute
- value - value for specified point (for point in specific location defined by pai lat and long)
How can I create from them a raster object? I've tried to use cbind to combine them:
# I prefer pacman::p_load(raster) to load package
library('raster')
# Sample very small subset of data:
lat <- c(84.6564178466797, 84.6564178466797, 83.3252105712891, 82.2175979614258,
80.3753433227539, 78.830451965332, 83.3252105712891)
long <- c(-145.316390991211, -70.6275939941406, -135.606842041016, -113.573654174805,
-102.370330810547, -104.610992431641, -79.5902481079102)
value <- c(0.379887759685516, 0.297680675983429, 0.259096682071686, 0.195639669895172,
0.259653329849243, 0.278579145669937, 0.333345)
myMatrix <- cbind(lat,long,value)
#this raster seems to be *incorrect*, because it shows: values: -145.3164, 84.65642 (min, max)
raster(myMatrix)
#Following causes an error (x cell sizes are not regular):
rasterFromXYZ(myMatrix)
but created object stores incorrect values.
Will I need to create a matrix first as described in this topic?