Giter VIP home page Giter VIP logo

Comments (5)

garrettgman avatar garrettgman commented on August 21, 2024

(note: I'm moving the content of this comment into its own issue, because it seems related and significant, but not the issue discussed here) - 7/13/09

It seems more complicated than it initially appeared. A single duration is a 1 x 2 data frame. So c(dur, dur) returns a list of four numeric objects which we can't add and subtract as durations, while list(dur, dur) returns a list of two duration objects.

it is less obvious how to put durations into a data frame in a satisfactory manner. The best I've found is

> data.frame(cbind(c(a,a), c(a,a)))
X1   X2
1 1, 1 1, 1
2 1, 1 1, 1

which doesn't print the durations correctly, but is of class "data.frame"

from lubridate.

garrettgman avatar garrettgman commented on August 21, 2024

(I deleted two comments about R crashing, because I located the error to side effects of a length.duration() I had made (and now removed)) - 7/13/09

from lubridate.

garrettgman avatar garrettgman commented on August 21, 2024

THE ISSUE HERE
To have arguments of differing lengths, the durations/POSIXts/difftimes must be stored in a list or vector or data.frame. As the default, these data structures have the class "list" (or whichever is appropriate) but not the class attributes of their individual elements: "duration" "POSIXt" or "difftime."

Hence, R does not call '+.duration' when adding lists of durations. It is unclear what R does call as base::'+.list' and base::'+.default' do not exist. Either way when a list is involved in addition, R automatically returns Error: non-numeric argument to binary operators

Do we write a '+.list' to screen for durations? I think this depends also on our decision of which data structures to store durations in and how (see related issue)

from lubridate.

hadley avatar hadley commented on August 21, 2024

Duration is just a data frame, so the natural combining operation is rbind. Have a look at the code for c.duration,+ and print.duration for the basic idea.

from lubridate.

garrettgman avatar garrettgman commented on August 21, 2024

The ops functions work for vectors of different lengths. If the different lengths are not multiples of each other it provides a warning message just as base::r does. But I wonder why R doesn't use an error message instead...

from lubridate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.