Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:34:09+00:00 2026-05-26T01:34:09+00:00

I have a function that takes a Date-object and returns one. However, when I

  • 0

I have a function that takes a Date-object and returns one. However, when I applied the function to a data.frame column using the mapply function, I ran into problems: I didn’t get Date-objects back, as expected, but numbers. Any idea how I could convert those to Date-objects? Also, I would be interested in what’s happening here. Help is really appreciated!

Minimal example:

#Define simple function that takes a date-object and returns a date-object
add_day <- function(dat) {return(dat + 1)}

#Set up data.frame with two date-object entries in one column
df <- data.frame(Col_A = c(as.Date("01/01/00", "%m/%d/%y"), as.Date("05/02/11", "%m/%d/%y")))
#That is the desired result: give a date-object to the function, get one back
add_day(df[1, "Col_A"]) #Returns [1] "2000-01-02"
add_day(df[2, "Col_A"]) #Returns [1] "2011-05-03"

#Why does it not work here? What do I get back?
mapply(add_day, df[, "Col_A"]) #Returns [1] 10958 15097; Why? What is that?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:34:10+00:00Added an answer on May 26, 2026 at 1:34 am

    Your function is returning ‘dates’, just not in the format you are used to. Dates are stored internally as days since [some fixed date]. (I can’t remember off the top of my head which one, and varies slightly by specific format.)

    If you wrap your mapply call in as.Date you’ll see the output you expect.

    To see what’s going on here, consider that mapply is using sapply under the hood. So for example:

    sapply(df[,1],add_day)
    [1] 10958 15097
    

    But remember that sapply by default is unlisting results for convenience. If we specify simplify = FALSE:

    sapply(df[,1],add_day,simplify = FALSE)
    [[1]]
    [1] "2000-01-02"
    
    [[2]]
    [1] "2011-05-03"
    

    So when R coerced the list to a vector, the class information is dropped and only the internal storage is retained, namely the number of days since [whatever that specific date is]. And of course, mapply also has a SIMPLIFY argument that acts in the same way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a function that takes a data.frame which represent intervals of data which
I have a function that takes a string date in the format 08/24/2010 and
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a function that takes a struct, and I'm trying to store its
I have a function that takes pointer to pointer to struct. struct ABC; void
I have a function that takes a string-like argument. I want to decide if
I have a function that takes a const D3DVECTOR3 *pos , but I have
I have a function that takes 2 parameters : 1 = XML file, 2
I have a function that takes variadic arguments, that I obtain from func_get_args() .
I have a function that takes longitude and latitude and converts it to x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.