Using filter clause in R group by function












0















I'm trying to get number of phone numbers per each day using group by, but I want to count only phones that are valid, how can I set this condition in filter option? (Maybe different solution?)



The data consists of a table with 4 columns:




  • CreatedDate

  • Calculation_id__c

  • Acc_Phone__c (phone no)

  • Acc_PhoneHLRStatus__c (the status about the phone no)


Data has some N/A values from time to time in all but the first column. The idea is to count how many calculations, phone numbers, valid/invalid phone numbers per day there are. I've managed to count the number of non-empty rows based on various columns but I need to add the "WHERE" clause to my group by statement which would take only valid/invalid phone numbers. This code works:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%


But this code produces an error:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)')


The error message is:



Error in filter_impl(.data, quo) : 
Evaluation error: object 'Acc_PhoneHLRStatus__c' not found.


I'm not sure if the syntax is okay, I'm not familiar in using R, thank you all for your help!










share|improve this question























  • Please check the column names of the dataset. May be there is some typo in the filter column name

    – akrun
    Dec 31 '18 at 11:20
















0















I'm trying to get number of phone numbers per each day using group by, but I want to count only phones that are valid, how can I set this condition in filter option? (Maybe different solution?)



The data consists of a table with 4 columns:




  • CreatedDate

  • Calculation_id__c

  • Acc_Phone__c (phone no)

  • Acc_PhoneHLRStatus__c (the status about the phone no)


Data has some N/A values from time to time in all but the first column. The idea is to count how many calculations, phone numbers, valid/invalid phone numbers per day there are. I've managed to count the number of non-empty rows based on various columns but I need to add the "WHERE" clause to my group by statement which would take only valid/invalid phone numbers. This code works:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%


But this code produces an error:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)')


The error message is:



Error in filter_impl(.data, quo) : 
Evaluation error: object 'Acc_PhoneHLRStatus__c' not found.


I'm not sure if the syntax is okay, I'm not familiar in using R, thank you all for your help!










share|improve this question























  • Please check the column names of the dataset. May be there is some typo in the filter column name

    – akrun
    Dec 31 '18 at 11:20














0












0








0








I'm trying to get number of phone numbers per each day using group by, but I want to count only phones that are valid, how can I set this condition in filter option? (Maybe different solution?)



The data consists of a table with 4 columns:




  • CreatedDate

  • Calculation_id__c

  • Acc_Phone__c (phone no)

  • Acc_PhoneHLRStatus__c (the status about the phone no)


Data has some N/A values from time to time in all but the first column. The idea is to count how many calculations, phone numbers, valid/invalid phone numbers per day there are. I've managed to count the number of non-empty rows based on various columns but I need to add the "WHERE" clause to my group by statement which would take only valid/invalid phone numbers. This code works:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%


But this code produces an error:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)')


The error message is:



Error in filter_impl(.data, quo) : 
Evaluation error: object 'Acc_PhoneHLRStatus__c' not found.


I'm not sure if the syntax is okay, I'm not familiar in using R, thank you all for your help!










share|improve this question














I'm trying to get number of phone numbers per each day using group by, but I want to count only phones that are valid, how can I set this condition in filter option? (Maybe different solution?)



The data consists of a table with 4 columns:




  • CreatedDate

  • Calculation_id__c

  • Acc_Phone__c (phone no)

  • Acc_PhoneHLRStatus__c (the status about the phone no)


Data has some N/A values from time to time in all but the first column. The idea is to count how many calculations, phone numbers, valid/invalid phone numbers per day there are. I've managed to count the number of non-empty rows based on various columns but I need to add the "WHERE" clause to my group by statement which would take only valid/invalid phone numbers. This code works:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%


But this code produces an error:



grouped_SF_hlr_status <- declaredSalesDF %>% 
group_by(CreatedDate) %>%
count(Acc_Phone__c) %>%
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)')


The error message is:



Error in filter_impl(.data, quo) : 
Evaluation error: object 'Acc_PhoneHLRStatus__c' not found.


I'm not sure if the syntax is okay, I'm not familiar in using R, thank you all for your help!







r group-by






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 31 '18 at 11:20









ArturArtur

195




195













  • Please check the column names of the dataset. May be there is some typo in the filter column name

    – akrun
    Dec 31 '18 at 11:20



















  • Please check the column names of the dataset. May be there is some typo in the filter column name

    – akrun
    Dec 31 '18 at 11:20

















Please check the column names of the dataset. May be there is some typo in the filter column name

– akrun
Dec 31 '18 at 11:20





Please check the column names of the dataset. May be there is some typo in the filter column name

– akrun
Dec 31 '18 at 11:20












1 Answer
1






active

oldest

votes


















0














I believe this is because when you count(), the data is mutated so that it shows the variable you are counting (Acc_Phone__c) and the frequency of that variable. I think if you inspect grouped_SF_hlr_status after running your first code chunk, that is what you would find. The other variables are lost because they wouldn't make sense any more given the individual cases they refer to have been grouped together.



In this instance, as you are only interested in the valid numbers, you should filter before counting. Try switching the lines of your code around so the filter goes first.



grouped_SF_hlr_status <- declaredSalesDF %>% 
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)') %>%
group_by(CreatedDate) %>%
count(Acc_Phone__c)


(I can't check if this works without your data, but logically that seems right to me. Let me know if it shows any error...)






share|improve this answer
























  • Thank you, that's exactly what I needed! :)

    – Artur
    Dec 31 '18 at 13:57











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%2f53986843%2fusing-filter-clause-in-r-group-by-function%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









0














I believe this is because when you count(), the data is mutated so that it shows the variable you are counting (Acc_Phone__c) and the frequency of that variable. I think if you inspect grouped_SF_hlr_status after running your first code chunk, that is what you would find. The other variables are lost because they wouldn't make sense any more given the individual cases they refer to have been grouped together.



In this instance, as you are only interested in the valid numbers, you should filter before counting. Try switching the lines of your code around so the filter goes first.



grouped_SF_hlr_status <- declaredSalesDF %>% 
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)') %>%
group_by(CreatedDate) %>%
count(Acc_Phone__c)


(I can't check if this works without your data, but logically that seems right to me. Let me know if it shows any error...)






share|improve this answer
























  • Thank you, that's exactly what I needed! :)

    – Artur
    Dec 31 '18 at 13:57
















0














I believe this is because when you count(), the data is mutated so that it shows the variable you are counting (Acc_Phone__c) and the frequency of that variable. I think if you inspect grouped_SF_hlr_status after running your first code chunk, that is what you would find. The other variables are lost because they wouldn't make sense any more given the individual cases they refer to have been grouped together.



In this instance, as you are only interested in the valid numbers, you should filter before counting. Try switching the lines of your code around so the filter goes first.



grouped_SF_hlr_status <- declaredSalesDF %>% 
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)') %>%
group_by(CreatedDate) %>%
count(Acc_Phone__c)


(I can't check if this works without your data, but logically that seems right to me. Let me know if it shows any error...)






share|improve this answer
























  • Thank you, that's exactly what I needed! :)

    – Artur
    Dec 31 '18 at 13:57














0












0








0







I believe this is because when you count(), the data is mutated so that it shows the variable you are counting (Acc_Phone__c) and the frequency of that variable. I think if you inspect grouped_SF_hlr_status after running your first code chunk, that is what you would find. The other variables are lost because they wouldn't make sense any more given the individual cases they refer to have been grouped together.



In this instance, as you are only interested in the valid numbers, you should filter before counting. Try switching the lines of your code around so the filter goes first.



grouped_SF_hlr_status <- declaredSalesDF %>% 
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)') %>%
group_by(CreatedDate) %>%
count(Acc_Phone__c)


(I can't check if this works without your data, but logically that seems right to me. Let me know if it shows any error...)






share|improve this answer













I believe this is because when you count(), the data is mutated so that it shows the variable you are counting (Acc_Phone__c) and the frequency of that variable. I think if you inspect grouped_SF_hlr_status after running your first code chunk, that is what you would find. The other variables are lost because they wouldn't make sense any more given the individual cases they refer to have been grouped together.



In this instance, as you are only interested in the valid numbers, you should filter before counting. Try switching the lines of your code around so the filter goes first.



grouped_SF_hlr_status <- declaredSalesDF %>% 
filter(Acc_PhoneHLRStatus__c == 'komórkowy(poprawny)') %>%
group_by(CreatedDate) %>%
count(Acc_Phone__c)


(I can't check if this works without your data, but logically that seems right to me. Let me know if it shows any error...)







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 31 '18 at 12:14









MeganMegan

363213




363213













  • Thank you, that's exactly what I needed! :)

    – Artur
    Dec 31 '18 at 13:57



















  • Thank you, that's exactly what I needed! :)

    – Artur
    Dec 31 '18 at 13:57

















Thank you, that's exactly what I needed! :)

– Artur
Dec 31 '18 at 13:57





Thank you, that's exactly what I needed! :)

– Artur
Dec 31 '18 at 13:57


















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%2f53986843%2fusing-filter-clause-in-r-group-by-function%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