Vector becomes null












-1














When I perform the following operation nothing goes wrong, however if I run the
below code for a second or third time my vector aaa vector becomes NULL type and I can´t repeat the operation unless I close R to re-open it, it absolutely makes no sense, even worse, when I change the vector for another vector R states that is also NULL type, any idea of what to do?



aaa=c()

for(i in 1:95){
for(j in 1:length(codigos[,1])){
if(Base[i,3]==codigos[j,1]){
aaa[i]=codigos[j,2]
Base[i,3]=codigos[j,2]
}
}
}









share|improve this question




















  • 4




    It is best to explain what you are trying to do. Provide example reproducible data and expected output.
    – zx8754
    Nov 22 at 20:47










  • maybe the if statement is always false so aaa is empty from the beggining.
    – Csd
    Nov 22 at 20:59










  • If you get some "result" the first time, and then nothing later , then it's probable that after the first run Base[i,3]==codigos[j,1] is never TRUE. Therefore, aaa[i]=codigos[j,2] is never run, and aaa stays at its "original value", which is NULL.
    – lbusett
    Nov 22 at 21:14










  • I forgot to mention, the first time I run the operation I do get results, the vector is fillep with actual values, but most of them are NA, do you think it has something to do?
    – Mario Coronel Maidana
    Nov 23 at 10:57










  • Difficult to say without seeing your data and knowing what you are trying to do. However, given the "logic" of your code, it is not unexpected that you get different results on different runs: Base[i,3]=codigos[j,2] modifies the Base d.f. on the first run. Since you use a condition on Base to decide what to do with aaa, different runs can have different results, unless you "reset" Base to its original value.
    – lbusett
    Nov 23 at 14:09


















-1














When I perform the following operation nothing goes wrong, however if I run the
below code for a second or third time my vector aaa vector becomes NULL type and I can´t repeat the operation unless I close R to re-open it, it absolutely makes no sense, even worse, when I change the vector for another vector R states that is also NULL type, any idea of what to do?



aaa=c()

for(i in 1:95){
for(j in 1:length(codigos[,1])){
if(Base[i,3]==codigos[j,1]){
aaa[i]=codigos[j,2]
Base[i,3]=codigos[j,2]
}
}
}









share|improve this question




















  • 4




    It is best to explain what you are trying to do. Provide example reproducible data and expected output.
    – zx8754
    Nov 22 at 20:47










  • maybe the if statement is always false so aaa is empty from the beggining.
    – Csd
    Nov 22 at 20:59










  • If you get some "result" the first time, and then nothing later , then it's probable that after the first run Base[i,3]==codigos[j,1] is never TRUE. Therefore, aaa[i]=codigos[j,2] is never run, and aaa stays at its "original value", which is NULL.
    – lbusett
    Nov 22 at 21:14










  • I forgot to mention, the first time I run the operation I do get results, the vector is fillep with actual values, but most of them are NA, do you think it has something to do?
    – Mario Coronel Maidana
    Nov 23 at 10:57










  • Difficult to say without seeing your data and knowing what you are trying to do. However, given the "logic" of your code, it is not unexpected that you get different results on different runs: Base[i,3]=codigos[j,2] modifies the Base d.f. on the first run. Since you use a condition on Base to decide what to do with aaa, different runs can have different results, unless you "reset" Base to its original value.
    – lbusett
    Nov 23 at 14:09
















-1












-1








-1







When I perform the following operation nothing goes wrong, however if I run the
below code for a second or third time my vector aaa vector becomes NULL type and I can´t repeat the operation unless I close R to re-open it, it absolutely makes no sense, even worse, when I change the vector for another vector R states that is also NULL type, any idea of what to do?



aaa=c()

for(i in 1:95){
for(j in 1:length(codigos[,1])){
if(Base[i,3]==codigos[j,1]){
aaa[i]=codigos[j,2]
Base[i,3]=codigos[j,2]
}
}
}









share|improve this question















When I perform the following operation nothing goes wrong, however if I run the
below code for a second or third time my vector aaa vector becomes NULL type and I can´t repeat the operation unless I close R to re-open it, it absolutely makes no sense, even worse, when I change the vector for another vector R states that is also NULL type, any idea of what to do?



aaa=c()

for(i in 1:95){
for(j in 1:length(codigos[,1])){
if(Base[i,3]==codigos[j,1]){
aaa[i]=codigos[j,2]
Base[i,3]=codigos[j,2]
}
}
}






r vector null






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 20:45









zx8754

29.1k76398




29.1k76398










asked Nov 22 at 20:21









Mario Coronel Maidana

1




1








  • 4




    It is best to explain what you are trying to do. Provide example reproducible data and expected output.
    – zx8754
    Nov 22 at 20:47










  • maybe the if statement is always false so aaa is empty from the beggining.
    – Csd
    Nov 22 at 20:59










  • If you get some "result" the first time, and then nothing later , then it's probable that after the first run Base[i,3]==codigos[j,1] is never TRUE. Therefore, aaa[i]=codigos[j,2] is never run, and aaa stays at its "original value", which is NULL.
    – lbusett
    Nov 22 at 21:14










  • I forgot to mention, the first time I run the operation I do get results, the vector is fillep with actual values, but most of them are NA, do you think it has something to do?
    – Mario Coronel Maidana
    Nov 23 at 10:57










  • Difficult to say without seeing your data and knowing what you are trying to do. However, given the "logic" of your code, it is not unexpected that you get different results on different runs: Base[i,3]=codigos[j,2] modifies the Base d.f. on the first run. Since you use a condition on Base to decide what to do with aaa, different runs can have different results, unless you "reset" Base to its original value.
    – lbusett
    Nov 23 at 14:09
















  • 4




    It is best to explain what you are trying to do. Provide example reproducible data and expected output.
    – zx8754
    Nov 22 at 20:47










  • maybe the if statement is always false so aaa is empty from the beggining.
    – Csd
    Nov 22 at 20:59










  • If you get some "result" the first time, and then nothing later , then it's probable that after the first run Base[i,3]==codigos[j,1] is never TRUE. Therefore, aaa[i]=codigos[j,2] is never run, and aaa stays at its "original value", which is NULL.
    – lbusett
    Nov 22 at 21:14










  • I forgot to mention, the first time I run the operation I do get results, the vector is fillep with actual values, but most of them are NA, do you think it has something to do?
    – Mario Coronel Maidana
    Nov 23 at 10:57










  • Difficult to say without seeing your data and knowing what you are trying to do. However, given the "logic" of your code, it is not unexpected that you get different results on different runs: Base[i,3]=codigos[j,2] modifies the Base d.f. on the first run. Since you use a condition on Base to decide what to do with aaa, different runs can have different results, unless you "reset" Base to its original value.
    – lbusett
    Nov 23 at 14:09










4




4




It is best to explain what you are trying to do. Provide example reproducible data and expected output.
– zx8754
Nov 22 at 20:47




It is best to explain what you are trying to do. Provide example reproducible data and expected output.
– zx8754
Nov 22 at 20:47












maybe the if statement is always false so aaa is empty from the beggining.
– Csd
Nov 22 at 20:59




maybe the if statement is always false so aaa is empty from the beggining.
– Csd
Nov 22 at 20:59












If you get some "result" the first time, and then nothing later , then it's probable that after the first run Base[i,3]==codigos[j,1] is never TRUE. Therefore, aaa[i]=codigos[j,2] is never run, and aaa stays at its "original value", which is NULL.
– lbusett
Nov 22 at 21:14




If you get some "result" the first time, and then nothing later , then it's probable that after the first run Base[i,3]==codigos[j,1] is never TRUE. Therefore, aaa[i]=codigos[j,2] is never run, and aaa stays at its "original value", which is NULL.
– lbusett
Nov 22 at 21:14












I forgot to mention, the first time I run the operation I do get results, the vector is fillep with actual values, but most of them are NA, do you think it has something to do?
– Mario Coronel Maidana
Nov 23 at 10:57




I forgot to mention, the first time I run the operation I do get results, the vector is fillep with actual values, but most of them are NA, do you think it has something to do?
– Mario Coronel Maidana
Nov 23 at 10:57












Difficult to say without seeing your data and knowing what you are trying to do. However, given the "logic" of your code, it is not unexpected that you get different results on different runs: Base[i,3]=codigos[j,2] modifies the Base d.f. on the first run. Since you use a condition on Base to decide what to do with aaa, different runs can have different results, unless you "reset" Base to its original value.
– lbusett
Nov 23 at 14:09






Difficult to say without seeing your data and knowing what you are trying to do. However, given the "logic" of your code, it is not unexpected that you get different results on different runs: Base[i,3]=codigos[j,2] modifies the Base d.f. on the first run. Since you use a condition on Base to decide what to do with aaa, different runs can have different results, unless you "reset" Base to its original value.
– lbusett
Nov 23 at 14:09



















active

oldest

votes











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%2f53437602%2fvector-becomes-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53437602%2fvector-becomes-null%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

Lallio

Unable to find Lightning Node

Futebolista