-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Using dplyr functions on grouped data frame with variable of class difftime generates error #390
Comments
What we do is check for attributes:
We don't know how to handle the |
This just bit me too. Where's the relevant code for the current special case? Surely that could be made more generic based on the class of the column... Oh, is it "all over the place" and in C++. The really annoying thing is that dplyr complains even if you don't use that column in your chain. My workaround is to use transform, eg: transform(mdmh, ahead=as.numeric(ahead)) %.% group_by(etc) %.% etc |
@romainfrancois can we add support for difftime objects too please? |
I've commited a series of fixes and some tests for handling of "difftime". Please @Henrik-P @barryrowlingson test again :) |
@barryrowlingson @romainfrancois FYI I'm still getting this error when trying to group the UK's National Travel Survey (NTS) by individual id. What's strange is that when I tried to provide a reproducible example, the error disappeared. If my df is ntstrips,
Then do this: |
@romainfrancois, Thanks a lot for your work. All the examples in my original post now runs smoothly using |
Apologies - just updated to 0.3 and seems to fix it. |
Hej, I came across a maybe confusing behaviour with dplyr and difftime. Using the example given above:
When I (wrongly ! ) try to use
If i do not include the |
Using
dplyr
data manipulation functions on a grouped data frame which contains a variable of classdifftime
generates the error:I illustrate this using some toy data with a grouping variable (grp), a column with some values (val), two date columns (date1, date2), and a variable of class
difftime
(the difference between date1 and date2):I tried to add the mean of vals within each group to the original data set. The desired output can be created using
ddply
:When I try to create the same output with
dplyr
, an error is generatedJust to check, the same error is generated when the
difftime
variable is itself subject to the calculation, e.g....or when using (toy examples of)
summarise
,filter
,select
orarrange
:The
difftime
variable does not cause any problem whenmutate
is used on an ungrouped data frame:...or on an ungrouped 'tbl_df':
Neither does the
difftime
variable cause any problem when variousdplyr
data manipulation functions are applied on a groupeddata.table
version of df:My current quick and dirty workaround is to convert the
difftime
variable tonumeric
:However, there are quite a few methods for the
difftime
class (see Detail in?difftime
). Thus, it would be nice ifdplyr
could handle grouped data frames containing a variable of classdifftime
.Search on SO and google for 'dplyr difftime "Error in eval(expr, envir, enclos)" : column has unsupported type' gave no hits.
Thanks a lot for your great work with a fantastic package.
Best regards,
Henrik
The text was updated successfully, but these errors were encountered: