New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem using nth() with POSIXct date #509

Closed
steadyfish opened this Issue Jul 25, 2014 · 8 comments

Comments

Projects
None yet
4 participants
@steadyfish

steadyfish commented Jul 25, 2014

Hi,

Thanks for making this wonderful package dplyr!

I'm facing an issue working with POSIXct dates and it seems very similar to this issue #194. The min() and max() functions work fine with dates, but nth() doesn't seem to retain the class information..

One can replicate this issue with the same example as @manuelreif reported in issue #194, just replacing the function min() with nth().

@romainfrancois romainfrancois added the bug label Jul 25, 2014

@romainfrancois

This comment has been minimized.

Member

romainfrancois commented Jul 27, 2014

Capturing modified example:

require(lubridate)
ID     <- rep(letters[1:4],each=5)
date   <-  ymd(paste0(sample(c(1960:2014),length(ID),replace=TRUE),sample(sprintf(fmt="%02d",1:12),length(ID),replace=TRUE),sample(sprintf(fmt="%02d",1:25),length(ID),replace=TRUE)))
number <-  rnorm(length(ID))
# create data.frame
d <- data.frame(ID,date,number)
# use dplyr
d_dplyr <- tbl_df(d)
d_dplyr %>% group_by(ID) %>% summarise(mindate=nth(date, 2))
@steadyfish

This comment has been minimized.

steadyfish commented Jul 30, 2014

to add, nth() also fails to retain the factor levels when applied on ordered factors.

Example:

 a = rep(seq(1,20,2),3)
 b = as.ordered(a)
 dat = data.frame(a,b)

 is(dat$b)
 [1] "ordered"             "factor"              "integer"             "oldClass"            "numeric"            
 [6] "vector"              "data.frameRowLabels"

 dat1 = dat %>%
   group_by(a) %>%
   summarise(der = nth(b,2))

 is(dat1$der)
 [1] "integer"             "numeric"             "vector"              "data.frameRowLabels"

@hadley hadley added this to the 0.3 milestone Aug 1, 2014

@hadley

This comment has been minimized.

Member

hadley commented Aug 1, 2014

@romainfrancois is there an implementation of nth() in the hybrid evaluator, or does this just need fixing in the R code?

@romainfrancois

This comment has been minimized.

Member

romainfrancois commented Sep 21, 2014

hybrid definitely has nth. Picking this up now.

@romainfrancois romainfrancois self-assigned this Sep 21, 2014

romainfrancois added a commit that referenced this issue Sep 21, 2014

Making TypedProcessor more useful and add a free function typed_proce…
…ssor

that uses tmpl deduction to create the right pointer

use this to fix nth for Date and POSIXct in the simple case. #509

romainfrancois added a commit that referenced this issue Sep 21, 2014

@romainfrancois

This comment has been minimized.

Member

romainfrancois commented Sep 21, 2014

Almost there. I only need to deal with factors now.

@nverwer

This comment has been minimized.

nverwer commented Nov 4, 2014

It is great that nth handles dates and factors now! Could you make the same changes for first and last, please?

@romainfrancois romainfrancois modified the milestones: 0.3.1, 0.3 Nov 4, 2014

@romainfrancois

This comment has been minimized.

Member

romainfrancois commented Nov 4, 2014

Reopening this to handle first and last as per @nverwer comment.

@nverwer

This comment has been minimized.

nverwer commented Nov 6, 2014

Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.