Which row in a SpatialPolygonsDataFrame by multipul logicals












1















I have a single SpatialPolygonsDataFrame in which I have 3 islands. On these islands, there are named locations however the names are not unique between islands. I have found a way to identify which names are replicated between the various island but I can not get back to which row they correspond to. Ideally I would find a way to access those rows so I can modify the location name to create name that's unique between islands.
Using the Meuse data set from sp I came up with this



library(sp)
data("meuse")
coordinates(meuse) <- ~ x + y
str(meuse)
a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]
dim(a)
subset(meuse, lime == "1")


The return of a is 0 but when you look at the last subset line there are clearly rows that fit that condition. Any suggestions on what I'm missing here or what I should be doing instead?










share|improve this question

























  • all the data on meuse has sold == "1"

    – Carlos Santillan
    Jan 3 at 2:40











  • Unclear what you are asking. a has zero rows because no soil == 0 in the dataset. In contrast, subset(meuse, soil == "1") has more than zero rows because there are soil == 1 in the dataset. Everything works as expected.

    – www
    Jan 3 at 4:03











  • thanks @CarlosSantillan and www there was a problem with my example. When I change soil to lime however, you can see that I am still unable to subset in the ways I'm expecting.

    – Reed
    Jan 3 at 21:24
















1















I have a single SpatialPolygonsDataFrame in which I have 3 islands. On these islands, there are named locations however the names are not unique between islands. I have found a way to identify which names are replicated between the various island but I can not get back to which row they correspond to. Ideally I would find a way to access those rows so I can modify the location name to create name that's unique between islands.
Using the Meuse data set from sp I came up with this



library(sp)
data("meuse")
coordinates(meuse) <- ~ x + y
str(meuse)
a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]
dim(a)
subset(meuse, lime == "1")


The return of a is 0 but when you look at the last subset line there are clearly rows that fit that condition. Any suggestions on what I'm missing here or what I should be doing instead?










share|improve this question

























  • all the data on meuse has sold == "1"

    – Carlos Santillan
    Jan 3 at 2:40











  • Unclear what you are asking. a has zero rows because no soil == 0 in the dataset. In contrast, subset(meuse, soil == "1") has more than zero rows because there are soil == 1 in the dataset. Everything works as expected.

    – www
    Jan 3 at 4:03











  • thanks @CarlosSantillan and www there was a problem with my example. When I change soil to lime however, you can see that I am still unable to subset in the ways I'm expecting.

    – Reed
    Jan 3 at 21:24














1












1








1








I have a single SpatialPolygonsDataFrame in which I have 3 islands. On these islands, there are named locations however the names are not unique between islands. I have found a way to identify which names are replicated between the various island but I can not get back to which row they correspond to. Ideally I would find a way to access those rows so I can modify the location name to create name that's unique between islands.
Using the Meuse data set from sp I came up with this



library(sp)
data("meuse")
coordinates(meuse) <- ~ x + y
str(meuse)
a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]
dim(a)
subset(meuse, lime == "1")


The return of a is 0 but when you look at the last subset line there are clearly rows that fit that condition. Any suggestions on what I'm missing here or what I should be doing instead?










share|improve this question
















I have a single SpatialPolygonsDataFrame in which I have 3 islands. On these islands, there are named locations however the names are not unique between islands. I have found a way to identify which names are replicated between the various island but I can not get back to which row they correspond to. Ideally I would find a way to access those rows so I can modify the location name to create name that's unique between islands.
Using the Meuse data set from sp I came up with this



library(sp)
data("meuse")
coordinates(meuse) <- ~ x + y
str(meuse)
a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]
dim(a)
subset(meuse, lime == "1")


The return of a is 0 but when you look at the last subset line there are clearly rows that fit that condition. Any suggestions on what I'm missing here or what I should be doing instead?







r sp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 21:22







Reed

















asked Jan 3 at 2:22









ReedReed

647




647













  • all the data on meuse has sold == "1"

    – Carlos Santillan
    Jan 3 at 2:40











  • Unclear what you are asking. a has zero rows because no soil == 0 in the dataset. In contrast, subset(meuse, soil == "1") has more than zero rows because there are soil == 1 in the dataset. Everything works as expected.

    – www
    Jan 3 at 4:03











  • thanks @CarlosSantillan and www there was a problem with my example. When I change soil to lime however, you can see that I am still unable to subset in the ways I'm expecting.

    – Reed
    Jan 3 at 21:24



















  • all the data on meuse has sold == "1"

    – Carlos Santillan
    Jan 3 at 2:40











  • Unclear what you are asking. a has zero rows because no soil == 0 in the dataset. In contrast, subset(meuse, soil == "1") has more than zero rows because there are soil == 1 in the dataset. Everything works as expected.

    – www
    Jan 3 at 4:03











  • thanks @CarlosSantillan and www there was a problem with my example. When I change soil to lime however, you can see that I am still unable to subset in the ways I'm expecting.

    – Reed
    Jan 3 at 21:24

















all the data on meuse has sold == "1"

– Carlos Santillan
Jan 3 at 2:40





all the data on meuse has sold == "1"

– Carlos Santillan
Jan 3 at 2:40













Unclear what you are asking. a has zero rows because no soil == 0 in the dataset. In contrast, subset(meuse, soil == "1") has more than zero rows because there are soil == 1 in the dataset. Everything works as expected.

– www
Jan 3 at 4:03





Unclear what you are asking. a has zero rows because no soil == 0 in the dataset. In contrast, subset(meuse, soil == "1") has more than zero rows because there are soil == 1 in the dataset. Everything works as expected.

– www
Jan 3 at 4:03













thanks @CarlosSantillan and www there was a problem with my example. When I change soil to lime however, you can see that I am still unable to subset in the ways I'm expecting.

– Reed
Jan 3 at 21:24





thanks @CarlosSantillan and www there was a problem with my example. When I change soil to lime however, you can see that I am still unable to subset in the ways I'm expecting.

– Reed
Jan 3 at 21:24












1 Answer
1






active

oldest

votes


















1














The problem is && in



a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]


As the documentation says,




& and && indicate logical AND and | and || indicate logical OR. The
shorter form performs elementwise comparisons in much the same way as
arithmetic operators. The longer form evaluates left to right
examining only the first element of each vector.




For instance,



c(TRUE, TRUE) && c(FALSE, TRUE)
# [1] FALSE
c(TRUE, TRUE) & c(FALSE, TRUE)
# [1] FALSE TRUE


So, instead you want



a <- meuse[meuse$lime == "0" & meuse$landuse == "Ah",]
dim(a)
# [1] 31 12





share|improve this answer
























  • @Reed, does it help?

    – Julius Vainora
    Jan 4 at 19:53











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015555%2fwhich-row-in-a-spatialpolygonsdataframe-by-multipul-logicals%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









1














The problem is && in



a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]


As the documentation says,




& and && indicate logical AND and | and || indicate logical OR. The
shorter form performs elementwise comparisons in much the same way as
arithmetic operators. The longer form evaluates left to right
examining only the first element of each vector.




For instance,



c(TRUE, TRUE) && c(FALSE, TRUE)
# [1] FALSE
c(TRUE, TRUE) & c(FALSE, TRUE)
# [1] FALSE TRUE


So, instead you want



a <- meuse[meuse$lime == "0" & meuse$landuse == "Ah",]
dim(a)
# [1] 31 12





share|improve this answer
























  • @Reed, does it help?

    – Julius Vainora
    Jan 4 at 19:53
















1














The problem is && in



a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]


As the documentation says,




& and && indicate logical AND and | and || indicate logical OR. The
shorter form performs elementwise comparisons in much the same way as
arithmetic operators. The longer form evaluates left to right
examining only the first element of each vector.




For instance,



c(TRUE, TRUE) && c(FALSE, TRUE)
# [1] FALSE
c(TRUE, TRUE) & c(FALSE, TRUE)
# [1] FALSE TRUE


So, instead you want



a <- meuse[meuse$lime == "0" & meuse$landuse == "Ah",]
dim(a)
# [1] 31 12





share|improve this answer
























  • @Reed, does it help?

    – Julius Vainora
    Jan 4 at 19:53














1












1








1







The problem is && in



a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]


As the documentation says,




& and && indicate logical AND and | and || indicate logical OR. The
shorter form performs elementwise comparisons in much the same way as
arithmetic operators. The longer form evaluates left to right
examining only the first element of each vector.




For instance,



c(TRUE, TRUE) && c(FALSE, TRUE)
# [1] FALSE
c(TRUE, TRUE) & c(FALSE, TRUE)
# [1] FALSE TRUE


So, instead you want



a <- meuse[meuse$lime == "0" & meuse$landuse == "Ah",]
dim(a)
# [1] 31 12





share|improve this answer













The problem is && in



a <- meuse[meuse$lime == "0" && meuse$landuse == "Ah",]


As the documentation says,




& and && indicate logical AND and | and || indicate logical OR. The
shorter form performs elementwise comparisons in much the same way as
arithmetic operators. The longer form evaluates left to right
examining only the first element of each vector.




For instance,



c(TRUE, TRUE) && c(FALSE, TRUE)
# [1] FALSE
c(TRUE, TRUE) & c(FALSE, TRUE)
# [1] FALSE TRUE


So, instead you want



a <- meuse[meuse$lime == "0" & meuse$landuse == "Ah",]
dim(a)
# [1] 31 12






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 21:37









Julius VainoraJulius Vainora

38.2k76685




38.2k76685













  • @Reed, does it help?

    – Julius Vainora
    Jan 4 at 19:53



















  • @Reed, does it help?

    – Julius Vainora
    Jan 4 at 19:53

















@Reed, does it help?

– Julius Vainora
Jan 4 at 19:53





@Reed, does it help?

– Julius Vainora
Jan 4 at 19:53




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015555%2fwhich-row-in-a-spatialpolygonsdataframe-by-multipul-logicals%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas