Another R error: “comparison of these types is not implemented”












0















This works as a standalone statement, but errors when implemented in a function:
Given a data frame dummyDF with columns Status and LastStatusChangeDate, this works:



> nrow(dummyDF[which(dummyDF$Status == "Confirmed" & dummyDF$LastStatusChangeDate < as.Date("2018-11-30")),])
[1] 9


But when I implement it in a function:



QueueLength <- function(df, Status, LastDate){
nrow(df[which(df$Status == Status & df$LastStatusChangeDate < as.Date(LastDate)),])
}


and call it thus:



QueueLength(dummyDF, "Confirmed", "2018-11-30")


I get this error:
Error in df$Status == Status :
comparison of these types is not implemented



So what is the type difference? I ran this line:



> typeof(dummyDF$Status)
[1] "list"


OK, so I'm trying to compare a single string to a list of strings. I get it, sort of, why that is a problem, but it doesn't account for the body of the function working perfectly fine when I execute it interactively as above.



Anyone have a thought on how to make this work in a function?
Thanks.










share|improve this question


















  • 2





    can you provide dummyDF so we can reproduce the error?

    – iod
    Nov 22 '18 at 0:58






  • 1





    Furher noodling around revealed that the "Status" column was produced by using lapply which created the values as a nested list. I wrapped the lapply() in unlist() and that cured THAT problem. One of these days I'll get my head around the apply() family. The error message has disappeared, but the function looks like it's only using the "LastStatusChangeDate" value in filtering. I'll work on it some more tomorrow and post again. Thanks.

    – Charles Knell
    Nov 22 '18 at 3:21













  • QueueLength <- function(df, Status, LastDate){ nrow(df[which(df$`Status` == Status & df$LastStatusChangeDate < as.Date(LastDate)),]) } doesn't work too?

    – Nutle
    Nov 22 '18 at 15:24











  • I never worked out what the problem was, but when I created dummDF as a tibble rather than as a dataframe, my problems disappeared. Generally I like to stick with base R, but there are good reasons these other packages exist. Hats off to Tidyverse.

    – Charles Knell
    Nov 22 '18 at 20:15
















0















This works as a standalone statement, but errors when implemented in a function:
Given a data frame dummyDF with columns Status and LastStatusChangeDate, this works:



> nrow(dummyDF[which(dummyDF$Status == "Confirmed" & dummyDF$LastStatusChangeDate < as.Date("2018-11-30")),])
[1] 9


But when I implement it in a function:



QueueLength <- function(df, Status, LastDate){
nrow(df[which(df$Status == Status & df$LastStatusChangeDate < as.Date(LastDate)),])
}


and call it thus:



QueueLength(dummyDF, "Confirmed", "2018-11-30")


I get this error:
Error in df$Status == Status :
comparison of these types is not implemented



So what is the type difference? I ran this line:



> typeof(dummyDF$Status)
[1] "list"


OK, so I'm trying to compare a single string to a list of strings. I get it, sort of, why that is a problem, but it doesn't account for the body of the function working perfectly fine when I execute it interactively as above.



Anyone have a thought on how to make this work in a function?
Thanks.










share|improve this question


















  • 2





    can you provide dummyDF so we can reproduce the error?

    – iod
    Nov 22 '18 at 0:58






  • 1





    Furher noodling around revealed that the "Status" column was produced by using lapply which created the values as a nested list. I wrapped the lapply() in unlist() and that cured THAT problem. One of these days I'll get my head around the apply() family. The error message has disappeared, but the function looks like it's only using the "LastStatusChangeDate" value in filtering. I'll work on it some more tomorrow and post again. Thanks.

    – Charles Knell
    Nov 22 '18 at 3:21













  • QueueLength <- function(df, Status, LastDate){ nrow(df[which(df$`Status` == Status & df$LastStatusChangeDate < as.Date(LastDate)),]) } doesn't work too?

    – Nutle
    Nov 22 '18 at 15:24











  • I never worked out what the problem was, but when I created dummDF as a tibble rather than as a dataframe, my problems disappeared. Generally I like to stick with base R, but there are good reasons these other packages exist. Hats off to Tidyverse.

    – Charles Knell
    Nov 22 '18 at 20:15














0












0








0








This works as a standalone statement, but errors when implemented in a function:
Given a data frame dummyDF with columns Status and LastStatusChangeDate, this works:



> nrow(dummyDF[which(dummyDF$Status == "Confirmed" & dummyDF$LastStatusChangeDate < as.Date("2018-11-30")),])
[1] 9


But when I implement it in a function:



QueueLength <- function(df, Status, LastDate){
nrow(df[which(df$Status == Status & df$LastStatusChangeDate < as.Date(LastDate)),])
}


and call it thus:



QueueLength(dummyDF, "Confirmed", "2018-11-30")


I get this error:
Error in df$Status == Status :
comparison of these types is not implemented



So what is the type difference? I ran this line:



> typeof(dummyDF$Status)
[1] "list"


OK, so I'm trying to compare a single string to a list of strings. I get it, sort of, why that is a problem, but it doesn't account for the body of the function working perfectly fine when I execute it interactively as above.



Anyone have a thought on how to make this work in a function?
Thanks.










share|improve this question














This works as a standalone statement, but errors when implemented in a function:
Given a data frame dummyDF with columns Status and LastStatusChangeDate, this works:



> nrow(dummyDF[which(dummyDF$Status == "Confirmed" & dummyDF$LastStatusChangeDate < as.Date("2018-11-30")),])
[1] 9


But when I implement it in a function:



QueueLength <- function(df, Status, LastDate){
nrow(df[which(df$Status == Status & df$LastStatusChangeDate < as.Date(LastDate)),])
}


and call it thus:



QueueLength(dummyDF, "Confirmed", "2018-11-30")


I get this error:
Error in df$Status == Status :
comparison of these types is not implemented



So what is the type difference? I ran this line:



> typeof(dummyDF$Status)
[1] "list"


OK, so I'm trying to compare a single string to a list of strings. I get it, sort of, why that is a problem, but it doesn't account for the body of the function working perfectly fine when I execute it interactively as above.



Anyone have a thought on how to make this work in a function?
Thanks.







r function dataframe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 0:54









Charles KnellCharles Knell

304




304








  • 2





    can you provide dummyDF so we can reproduce the error?

    – iod
    Nov 22 '18 at 0:58






  • 1





    Furher noodling around revealed that the "Status" column was produced by using lapply which created the values as a nested list. I wrapped the lapply() in unlist() and that cured THAT problem. One of these days I'll get my head around the apply() family. The error message has disappeared, but the function looks like it's only using the "LastStatusChangeDate" value in filtering. I'll work on it some more tomorrow and post again. Thanks.

    – Charles Knell
    Nov 22 '18 at 3:21













  • QueueLength <- function(df, Status, LastDate){ nrow(df[which(df$`Status` == Status & df$LastStatusChangeDate < as.Date(LastDate)),]) } doesn't work too?

    – Nutle
    Nov 22 '18 at 15:24











  • I never worked out what the problem was, but when I created dummDF as a tibble rather than as a dataframe, my problems disappeared. Generally I like to stick with base R, but there are good reasons these other packages exist. Hats off to Tidyverse.

    – Charles Knell
    Nov 22 '18 at 20:15














  • 2





    can you provide dummyDF so we can reproduce the error?

    – iod
    Nov 22 '18 at 0:58






  • 1





    Furher noodling around revealed that the "Status" column was produced by using lapply which created the values as a nested list. I wrapped the lapply() in unlist() and that cured THAT problem. One of these days I'll get my head around the apply() family. The error message has disappeared, but the function looks like it's only using the "LastStatusChangeDate" value in filtering. I'll work on it some more tomorrow and post again. Thanks.

    – Charles Knell
    Nov 22 '18 at 3:21













  • QueueLength <- function(df, Status, LastDate){ nrow(df[which(df$`Status` == Status & df$LastStatusChangeDate < as.Date(LastDate)),]) } doesn't work too?

    – Nutle
    Nov 22 '18 at 15:24











  • I never worked out what the problem was, but when I created dummDF as a tibble rather than as a dataframe, my problems disappeared. Generally I like to stick with base R, but there are good reasons these other packages exist. Hats off to Tidyverse.

    – Charles Knell
    Nov 22 '18 at 20:15








2




2





can you provide dummyDF so we can reproduce the error?

– iod
Nov 22 '18 at 0:58





can you provide dummyDF so we can reproduce the error?

– iod
Nov 22 '18 at 0:58




1




1





Furher noodling around revealed that the "Status" column was produced by using lapply which created the values as a nested list. I wrapped the lapply() in unlist() and that cured THAT problem. One of these days I'll get my head around the apply() family. The error message has disappeared, but the function looks like it's only using the "LastStatusChangeDate" value in filtering. I'll work on it some more tomorrow and post again. Thanks.

– Charles Knell
Nov 22 '18 at 3:21







Furher noodling around revealed that the "Status" column was produced by using lapply which created the values as a nested list. I wrapped the lapply() in unlist() and that cured THAT problem. One of these days I'll get my head around the apply() family. The error message has disappeared, but the function looks like it's only using the "LastStatusChangeDate" value in filtering. I'll work on it some more tomorrow and post again. Thanks.

– Charles Knell
Nov 22 '18 at 3:21















QueueLength <- function(df, Status, LastDate){ nrow(df[which(df$`Status` == Status & df$LastStatusChangeDate < as.Date(LastDate)),]) } doesn't work too?

– Nutle
Nov 22 '18 at 15:24





QueueLength <- function(df, Status, LastDate){ nrow(df[which(df$`Status` == Status & df$LastStatusChangeDate < as.Date(LastDate)),]) } doesn't work too?

– Nutle
Nov 22 '18 at 15:24













I never worked out what the problem was, but when I created dummDF as a tibble rather than as a dataframe, my problems disappeared. Generally I like to stick with base R, but there are good reasons these other packages exist. Hats off to Tidyverse.

– Charles Knell
Nov 22 '18 at 20:15





I never worked out what the problem was, but when I created dummDF as a tibble rather than as a dataframe, my problems disappeared. Generally I like to stick with base R, but there are good reasons these other packages exist. Hats off to Tidyverse.

– Charles Knell
Nov 22 '18 at 20:15












0






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%2f53422487%2fanother-r-error-comparison-of-these-types-is-not-implemented%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422487%2fanother-r-error-comparison-of-these-types-is-not-implemented%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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith