What can do I do to correct Error in missing object (R 3.0.3; performing Cokriging)?
library(rgdal)
library(maptools)
library(gstat)
library(sp)
data <- read.table("meuse.txt", sep="", header=TRUE) # read txt file
# transform the data frame into a spatial data frame
coordinates(data) <- ~ x + y
## Set the coordinate system
proj4string(data) <- CRS("+init=epsg:4326")
## the epsg numbers can be found here: http://spatialreference.org/ref/
# import the border shp file
border <- readOGR("meuse_area.shp", "meuse_area")
proj4string(border) <- CRS("+init=epsg:4326")
# import a raster from a ArcInfo ASCII format
zinc <- read.asciigrid("zinc.asc")
proj4string(zinc) <- CRS("+init=epsg:4326")
# Let's first create a prediction grid for the interpolation, starting from
# the shape file
vals <- border@bbox
deltaLong <- as.integer((vals[1, 2] - vals[1, 1]) + 1.5)
deltaLat <- as.integer((vals[2, 2] - vals[2, 1]) + 1.5)
gridRes <- 0.5 # change this value to change the grid size (in metres)
gridSizeX <- deltaLong / gridRes
gridSizeY <- deltaLat / gridRes
grd <- GridTopology(vals[, 1], c(gridRes, gridRes), c(gridSizeX, gridSizeY))
pts <- SpatialPoints(coordinates(grd))
pts1 <- SpatialPointsDataFrame(as.data.frame(pts),
data=as.data.frame(rep(1, nrow(as.data.frame(pts)))))
Overlay <- overlay(pts1, border)
pts1$border <- Overlay
nona <- na.exclude(as.data.frame(pts1))
coordinates(nona) <- ~ x + y
gridded(nona) <- TRUE
proj4string(nona) <- CRS("+init=epsg:4326") # remember to set the coordinate
# system also for the prediction grid
writeAsciiGrid(nona, "prediction_grid.asc")
# For the Co-kriging we need to obtain the value of the covariate for each
# observation
over <- overlay(zinc, data)
data$zinc <- over$zinc.asc
str(as.data.frame(data))
# also the prediction grid need to be overlayed with the covariate
over <- overlay(zinc, nona)
nona$zinc <- over$zinc.asc
# for the cokriging, the first thing to do is create an object with the
# function gstat() that contains both the variable and the covariate
str(data)
complete.cases("data")
str(zinc)
complete.cases("zinc")
g <- gstat(id="lead", formula=lead ~ 1, data=data)
g <- gstat(g, id="zinc", formula=zinc ~ 1, data=data)
# Fitting the variogram
# first, plot the residual variogram
vario <- variogram(g)
Error in na.fail.default(list(zinc = c(NA, NA, NA, NA, NA, NA, NA, NA,
: missing values in object
I know that there is no missing in zinc when I edit the object in Notepad. What did I miss? There is no NA in zinc.asc.These are my data.
I want to perform cokriging and I am stuck with variogram.
r
|
show 2 more comments
library(rgdal)
library(maptools)
library(gstat)
library(sp)
data <- read.table("meuse.txt", sep="", header=TRUE) # read txt file
# transform the data frame into a spatial data frame
coordinates(data) <- ~ x + y
## Set the coordinate system
proj4string(data) <- CRS("+init=epsg:4326")
## the epsg numbers can be found here: http://spatialreference.org/ref/
# import the border shp file
border <- readOGR("meuse_area.shp", "meuse_area")
proj4string(border) <- CRS("+init=epsg:4326")
# import a raster from a ArcInfo ASCII format
zinc <- read.asciigrid("zinc.asc")
proj4string(zinc) <- CRS("+init=epsg:4326")
# Let's first create a prediction grid for the interpolation, starting from
# the shape file
vals <- border@bbox
deltaLong <- as.integer((vals[1, 2] - vals[1, 1]) + 1.5)
deltaLat <- as.integer((vals[2, 2] - vals[2, 1]) + 1.5)
gridRes <- 0.5 # change this value to change the grid size (in metres)
gridSizeX <- deltaLong / gridRes
gridSizeY <- deltaLat / gridRes
grd <- GridTopology(vals[, 1], c(gridRes, gridRes), c(gridSizeX, gridSizeY))
pts <- SpatialPoints(coordinates(grd))
pts1 <- SpatialPointsDataFrame(as.data.frame(pts),
data=as.data.frame(rep(1, nrow(as.data.frame(pts)))))
Overlay <- overlay(pts1, border)
pts1$border <- Overlay
nona <- na.exclude(as.data.frame(pts1))
coordinates(nona) <- ~ x + y
gridded(nona) <- TRUE
proj4string(nona) <- CRS("+init=epsg:4326") # remember to set the coordinate
# system also for the prediction grid
writeAsciiGrid(nona, "prediction_grid.asc")
# For the Co-kriging we need to obtain the value of the covariate for each
# observation
over <- overlay(zinc, data)
data$zinc <- over$zinc.asc
str(as.data.frame(data))
# also the prediction grid need to be overlayed with the covariate
over <- overlay(zinc, nona)
nona$zinc <- over$zinc.asc
# for the cokriging, the first thing to do is create an object with the
# function gstat() that contains both the variable and the covariate
str(data)
complete.cases("data")
str(zinc)
complete.cases("zinc")
g <- gstat(id="lead", formula=lead ~ 1, data=data)
g <- gstat(g, id="zinc", formula=zinc ~ 1, data=data)
# Fitting the variogram
# first, plot the residual variogram
vario <- variogram(g)
Error in na.fail.default(list(zinc = c(NA, NA, NA, NA, NA, NA, NA, NA,
: missing values in object
I know that there is no missing in zinc when I edit the object in Notepad. What did I miss? There is no NA in zinc.asc.These are my data.
I want to perform cokriging and I am stuck with variogram.
r
Could not run Line 37raster::overlay(pts1, border)
.
– jay.sf
Mar 15 '18 at 8:17
Can you suggest any other way? For me, it's running fine.
– user2543
Mar 15 '18 at 9:49
Don't know, I just run your code and got an error in this line. Perhaps unload all packages first to reproduce.
– jay.sf
Mar 15 '18 at 9:59
Was it really an error or just a warning message for deprecated function? I just ignored the warning message since it was not an error.
– user2543
Mar 15 '18 at 10:33
Overlay <- overlay(pts1, border)
yields Error in overlay(pts1, border) : could not find function "overlay", andOverlay <- raster::overlay(pts1, border)
yields Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPointsDataFrame", "SpatialPolygonsDataFrame"’
– jay.sf
Mar 15 '18 at 10:39
|
show 2 more comments
library(rgdal)
library(maptools)
library(gstat)
library(sp)
data <- read.table("meuse.txt", sep="", header=TRUE) # read txt file
# transform the data frame into a spatial data frame
coordinates(data) <- ~ x + y
## Set the coordinate system
proj4string(data) <- CRS("+init=epsg:4326")
## the epsg numbers can be found here: http://spatialreference.org/ref/
# import the border shp file
border <- readOGR("meuse_area.shp", "meuse_area")
proj4string(border) <- CRS("+init=epsg:4326")
# import a raster from a ArcInfo ASCII format
zinc <- read.asciigrid("zinc.asc")
proj4string(zinc) <- CRS("+init=epsg:4326")
# Let's first create a prediction grid for the interpolation, starting from
# the shape file
vals <- border@bbox
deltaLong <- as.integer((vals[1, 2] - vals[1, 1]) + 1.5)
deltaLat <- as.integer((vals[2, 2] - vals[2, 1]) + 1.5)
gridRes <- 0.5 # change this value to change the grid size (in metres)
gridSizeX <- deltaLong / gridRes
gridSizeY <- deltaLat / gridRes
grd <- GridTopology(vals[, 1], c(gridRes, gridRes), c(gridSizeX, gridSizeY))
pts <- SpatialPoints(coordinates(grd))
pts1 <- SpatialPointsDataFrame(as.data.frame(pts),
data=as.data.frame(rep(1, nrow(as.data.frame(pts)))))
Overlay <- overlay(pts1, border)
pts1$border <- Overlay
nona <- na.exclude(as.data.frame(pts1))
coordinates(nona) <- ~ x + y
gridded(nona) <- TRUE
proj4string(nona) <- CRS("+init=epsg:4326") # remember to set the coordinate
# system also for the prediction grid
writeAsciiGrid(nona, "prediction_grid.asc")
# For the Co-kriging we need to obtain the value of the covariate for each
# observation
over <- overlay(zinc, data)
data$zinc <- over$zinc.asc
str(as.data.frame(data))
# also the prediction grid need to be overlayed with the covariate
over <- overlay(zinc, nona)
nona$zinc <- over$zinc.asc
# for the cokriging, the first thing to do is create an object with the
# function gstat() that contains both the variable and the covariate
str(data)
complete.cases("data")
str(zinc)
complete.cases("zinc")
g <- gstat(id="lead", formula=lead ~ 1, data=data)
g <- gstat(g, id="zinc", formula=zinc ~ 1, data=data)
# Fitting the variogram
# first, plot the residual variogram
vario <- variogram(g)
Error in na.fail.default(list(zinc = c(NA, NA, NA, NA, NA, NA, NA, NA,
: missing values in object
I know that there is no missing in zinc when I edit the object in Notepad. What did I miss? There is no NA in zinc.asc.These are my data.
I want to perform cokriging and I am stuck with variogram.
r
library(rgdal)
library(maptools)
library(gstat)
library(sp)
data <- read.table("meuse.txt", sep="", header=TRUE) # read txt file
# transform the data frame into a spatial data frame
coordinates(data) <- ~ x + y
## Set the coordinate system
proj4string(data) <- CRS("+init=epsg:4326")
## the epsg numbers can be found here: http://spatialreference.org/ref/
# import the border shp file
border <- readOGR("meuse_area.shp", "meuse_area")
proj4string(border) <- CRS("+init=epsg:4326")
# import a raster from a ArcInfo ASCII format
zinc <- read.asciigrid("zinc.asc")
proj4string(zinc) <- CRS("+init=epsg:4326")
# Let's first create a prediction grid for the interpolation, starting from
# the shape file
vals <- border@bbox
deltaLong <- as.integer((vals[1, 2] - vals[1, 1]) + 1.5)
deltaLat <- as.integer((vals[2, 2] - vals[2, 1]) + 1.5)
gridRes <- 0.5 # change this value to change the grid size (in metres)
gridSizeX <- deltaLong / gridRes
gridSizeY <- deltaLat / gridRes
grd <- GridTopology(vals[, 1], c(gridRes, gridRes), c(gridSizeX, gridSizeY))
pts <- SpatialPoints(coordinates(grd))
pts1 <- SpatialPointsDataFrame(as.data.frame(pts),
data=as.data.frame(rep(1, nrow(as.data.frame(pts)))))
Overlay <- overlay(pts1, border)
pts1$border <- Overlay
nona <- na.exclude(as.data.frame(pts1))
coordinates(nona) <- ~ x + y
gridded(nona) <- TRUE
proj4string(nona) <- CRS("+init=epsg:4326") # remember to set the coordinate
# system also for the prediction grid
writeAsciiGrid(nona, "prediction_grid.asc")
# For the Co-kriging we need to obtain the value of the covariate for each
# observation
over <- overlay(zinc, data)
data$zinc <- over$zinc.asc
str(as.data.frame(data))
# also the prediction grid need to be overlayed with the covariate
over <- overlay(zinc, nona)
nona$zinc <- over$zinc.asc
# for the cokriging, the first thing to do is create an object with the
# function gstat() that contains both the variable and the covariate
str(data)
complete.cases("data")
str(zinc)
complete.cases("zinc")
g <- gstat(id="lead", formula=lead ~ 1, data=data)
g <- gstat(g, id="zinc", formula=zinc ~ 1, data=data)
# Fitting the variogram
# first, plot the residual variogram
vario <- variogram(g)
Error in na.fail.default(list(zinc = c(NA, NA, NA, NA, NA, NA, NA, NA,
: missing values in object
I know that there is no missing in zinc when I edit the object in Notepad. What did I miss? There is no NA in zinc.asc.These are my data.
I want to perform cokriging and I am stuck with variogram.
r
r
edited Mar 15 '18 at 10:03
jay.sf
5,21721639
5,21721639
asked Mar 15 '18 at 7:18
user2543user2543
1035
1035
Could not run Line 37raster::overlay(pts1, border)
.
– jay.sf
Mar 15 '18 at 8:17
Can you suggest any other way? For me, it's running fine.
– user2543
Mar 15 '18 at 9:49
Don't know, I just run your code and got an error in this line. Perhaps unload all packages first to reproduce.
– jay.sf
Mar 15 '18 at 9:59
Was it really an error or just a warning message for deprecated function? I just ignored the warning message since it was not an error.
– user2543
Mar 15 '18 at 10:33
Overlay <- overlay(pts1, border)
yields Error in overlay(pts1, border) : could not find function "overlay", andOverlay <- raster::overlay(pts1, border)
yields Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPointsDataFrame", "SpatialPolygonsDataFrame"’
– jay.sf
Mar 15 '18 at 10:39
|
show 2 more comments
Could not run Line 37raster::overlay(pts1, border)
.
– jay.sf
Mar 15 '18 at 8:17
Can you suggest any other way? For me, it's running fine.
– user2543
Mar 15 '18 at 9:49
Don't know, I just run your code and got an error in this line. Perhaps unload all packages first to reproduce.
– jay.sf
Mar 15 '18 at 9:59
Was it really an error or just a warning message for deprecated function? I just ignored the warning message since it was not an error.
– user2543
Mar 15 '18 at 10:33
Overlay <- overlay(pts1, border)
yields Error in overlay(pts1, border) : could not find function "overlay", andOverlay <- raster::overlay(pts1, border)
yields Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPointsDataFrame", "SpatialPolygonsDataFrame"’
– jay.sf
Mar 15 '18 at 10:39
Could not run Line 37
raster::overlay(pts1, border)
.– jay.sf
Mar 15 '18 at 8:17
Could not run Line 37
raster::overlay(pts1, border)
.– jay.sf
Mar 15 '18 at 8:17
Can you suggest any other way? For me, it's running fine.
– user2543
Mar 15 '18 at 9:49
Can you suggest any other way? For me, it's running fine.
– user2543
Mar 15 '18 at 9:49
Don't know, I just run your code and got an error in this line. Perhaps unload all packages first to reproduce.
– jay.sf
Mar 15 '18 at 9:59
Don't know, I just run your code and got an error in this line. Perhaps unload all packages first to reproduce.
– jay.sf
Mar 15 '18 at 9:59
Was it really an error or just a warning message for deprecated function? I just ignored the warning message since it was not an error.
– user2543
Mar 15 '18 at 10:33
Was it really an error or just a warning message for deprecated function? I just ignored the warning message since it was not an error.
– user2543
Mar 15 '18 at 10:33
Overlay <- overlay(pts1, border)
yields Error in overlay(pts1, border) : could not find function "overlay", and Overlay <- raster::overlay(pts1, border)
yields Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPointsDataFrame", "SpatialPolygonsDataFrame"’– jay.sf
Mar 15 '18 at 10:39
Overlay <- overlay(pts1, border)
yields Error in overlay(pts1, border) : could not find function "overlay", and Overlay <- raster::overlay(pts1, border)
yields Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPointsDataFrame", "SpatialPolygonsDataFrame"’– jay.sf
Mar 15 '18 at 10:39
|
show 2 more comments
1 Answer
1
active
oldest
votes
One cause of the confusion here may be that sp used to include it's own overlay function.
https://www.rdocumentation.org/packages/sp/versions/0.9-7/topics/overlay
However the most recent version of the sp package replaced the "overlay" function with "over". I do no believe raster::overlay behaves the same as the overlay function from sp 0.9-7
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49293561%2fwhat-can-do-i-do-to-correct-error-in-missing-object-r-3-0-3-performing-cokrigi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One cause of the confusion here may be that sp used to include it's own overlay function.
https://www.rdocumentation.org/packages/sp/versions/0.9-7/topics/overlay
However the most recent version of the sp package replaced the "overlay" function with "over". I do no believe raster::overlay behaves the same as the overlay function from sp 0.9-7
add a comment |
One cause of the confusion here may be that sp used to include it's own overlay function.
https://www.rdocumentation.org/packages/sp/versions/0.9-7/topics/overlay
However the most recent version of the sp package replaced the "overlay" function with "over". I do no believe raster::overlay behaves the same as the overlay function from sp 0.9-7
add a comment |
One cause of the confusion here may be that sp used to include it's own overlay function.
https://www.rdocumentation.org/packages/sp/versions/0.9-7/topics/overlay
However the most recent version of the sp package replaced the "overlay" function with "over". I do no believe raster::overlay behaves the same as the overlay function from sp 0.9-7
One cause of the confusion here may be that sp used to include it's own overlay function.
https://www.rdocumentation.org/packages/sp/versions/0.9-7/topics/overlay
However the most recent version of the sp package replaced the "overlay" function with "over". I do no believe raster::overlay behaves the same as the overlay function from sp 0.9-7
edited Dec 31 '18 at 20:29
answered Dec 31 '18 at 19:36
M.BergenM.Bergen
113
113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49293561%2fwhat-can-do-i-do-to-correct-error-in-missing-object-r-3-0-3-performing-cokrigi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could not run Line 37
raster::overlay(pts1, border)
.– jay.sf
Mar 15 '18 at 8:17
Can you suggest any other way? For me, it's running fine.
– user2543
Mar 15 '18 at 9:49
Don't know, I just run your code and got an error in this line. Perhaps unload all packages first to reproduce.
– jay.sf
Mar 15 '18 at 9:59
Was it really an error or just a warning message for deprecated function? I just ignored the warning message since it was not an error.
– user2543
Mar 15 '18 at 10:33
Overlay <- overlay(pts1, border)
yields Error in overlay(pts1, border) : could not find function "overlay", andOverlay <- raster::overlay(pts1, border)
yields Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPointsDataFrame", "SpatialPolygonsDataFrame"’– jay.sf
Mar 15 '18 at 10:39