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

  • SEARCH
  • Home
  • 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 8708251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:05:06+00:00 2026-06-13T04:05:06+00:00

I am calculating a linear regression between an age (numeric) vector and a date

  • 0

I am calculating a linear regression between an age (numeric) vector and a date (POSIXct) vector. What is the most convenient way to transform the date so that cor is happy with it?

  • 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-06-13T04:05:07+00:00Added an answer on June 13, 2026 at 4:05 am

    As mentionned in @Chase’s comment, you can use directly your dates in cor if you transform them into numeric objects with as.numeric.

    #First some dummy data:
    age<-ceiling(runif(20,min=25,max=45))
    joindate<-sample(seq(as.Date("01/01/1990","%d/%m/%Y"), 
                         as.Date("31/12/2010","%d/%m/%Y"), by="day"), 20)
    age
    [1] 35 33 33 30 39 30 32 26 45 37 28 44 35 31 39 44 44 40 29 39
    joindate
     [1] "1999-07-03" "2006-08-09" "2001-11-22" "2003-02-11" "1991-06-23" "2007-04-20" "1993-04-28" "1997-04-08" "1999-08-16"
    [10] "2005-02-17" "2002-11-01" "1991-09-17" "2006-05-03" "1995-12-02" "2007-06-20" "2000-02-26" "2005-10-01" "1997-06-13"
    [19] "2007-06-09" "1994-11-27"
    
    as.numeric(joindate) 
    # Dates are transformed into a number that corresponds to the number of days since the origin date (as a convention the 1970/01/01)
     [1] 10775 13369 11648 12094  7843 13623  8518  9959 10819 12831 11992  7929 13271  9466 13684 11013 13057 10025 13673  9096
    
    cor.test(age, as.numeric(joindate))
    
        Pearson's product-moment correlation
    
    data:  age and as.numeric(joindate) 
    t = -0.9641, df = 18, p-value = 0.3478
    alternative hypothesis: true correlation is not equal to 0 
    95 percent confidence interval:
     -0.6048037  0.2449517 
    sample estimates:
           cor 
    -0.2215884 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Calculating the Difference Between Two Java Date Instances How do I get
I am calculating the number of days between the 'from' and 'to' date. For
I'm trying to work out the most efficient method to find the linear regression
I'd like to specify an SVG linear gradient in a way that exactly duplicates
I am calculating something that takes some time. For that I've created an inner
I am calculating one parameter(X) this way: <?php $link=mysql_connect(localhost,root,); mysql_select_db(hand); $result = mysql_query(select *
I have a problem calculating the distance between two geopoints. The geopoints are: position1
I am calculating current time Interval using following codes: NSTimeInterval tInt=[[NSDate date] timeIntervalSince1970]; int
I'm calculating linear regressions based on a data set. I do not know the
I had some code calculating a linear combination on maps of floats, and ran

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.