Error in as.Date.numeric(13131) : ‘origin’ must be supplied

Working with dates is a fundamental part of data analysis in R. Whether you’re analyzing financial records, customer transactions, healthcare data, or time series datasets, you’ll frequently need to convert numeric values into proper date objects.

One common error that R users encounter is:

Error in as.Date.numeric(13131) :
  'origin' must be supplied

This error occurs when attempting to convert a numeric value to a Date object without specifying the starting reference date, also known as the origin.

In this tutorial, you’ll learn:

  • Why this error occurs
  • How to reproduce the error
  • Multiple ways to fix it
  • How R stores dates internally
  • Common date origins used in R, Excel, and databases
  • Best practices for date conversion

Why Does This Error Occur?

In R, dates are stored internally as the number of days since a specific reference date.

For example:

as.Date("1970-01-01")

represents day 0 in R’s default date system.

When you provide a numeric value such as:

13131

R doesn’t know which starting date should be used to interpret that number.

Is it:

  • 13,131 days since 1970-01-01?
  • 13,131 days since 1986-01-01?
  • 13,131 days since an Excel date origin?

Without this information, R cannot perform the conversion and returns an error.

Reproducing the Error

Suppose we attempt to convert a numeric value directly into a Date object.

as.Date(13131)

Output:

Error in as.Date.numeric(13131) :
  'origin' must be supplied

The error indicates that R requires an origin date before it can convert the numeric value.

Understanding the Origin Argument

The origin argument specifies the starting date from which the numeric value is measured.

General syntax:

as.Date(numeric_value, origin = "YYYY-MM-DD")

Where:

  • numeric_value = number of days
  • origin = reference date

R adds the specified number of days to the origin date and returns the resulting date.

Solution: Supply the Origin Argument

To fix the error, specify the appropriate origin.

as.Date(13131, origin = "1986-01-01")

Output:

[1] "2021-12-14"

Success! R now knows how to interpret the numeric value.

How the Calculation Works

The value:

13131

represents:

13131 days after 1986-01-01

R performs the calculation automatically:

1986-01-01 + 13131 days

Result:

2021-12-14

R’s Default Date Origin

The most common origin used in R is:

1970-01-01

This follows the Unix Epoch standard.

Example:

as.Date(20000, origin = "1970-01-01")

Output:

[1] "2024-10-04"

Converting Dates Back to Numeric Values

You can also convert dates into the number of days since an origin.

as.numeric(as.Date("2025-01-01"))

Output:

[1] 20089

This means January 1, 2025 is 20,089 days after January 1, 1970.

Working with Excel Dates

A common use case involves importing dates from Excel.

Excel stores dates as serial numbers.

For example:

excel_date <- 45000

Convert Excel dates using:

as.Date(excel_date, origin = "1899-12-30")

Output:

[1] "2023-03-15"

Why Use “1899-12-30”?

Excel incorrectly treats 1900 as a leap year, so the standard Excel origin used in R is:

origin = "1899-12-30"

Converting Multiple Numeric Dates

Suppose you have a vector of numeric dates.

dates <- c(13131, 13200, 13300)

Convert them all at once:

as.Date(dates, origin = "1986-01-01")

Output:

[1] "2021-12-14"
[2] "2022-02-21"
[3] "2022-06-01"

Working with Data Frames

Consider the following dataset:

df <- data.frame(
  id = 1:3,
  date_num = c(13131, 13200, 13300)
)

df

Convert the numeric date column:

df$date <- as.Date(
  df$date_num,
  origin = "1986-01-01"
)

df

Output:

  id date_num       date
1  1    13131 2021-12-14
2  2    13200 2022-02-21
3  3    13300 2022-06-01

Common Origins Used in Data Analysis

SystemOrigin
R / Unix1970-01-01
Excel (Windows)1899-12-30
Excel (Mac, older versions)1904-01-01
Custom Business SystemsUser-defined

Always verify the source of your data before selecting an origin.

Common Mistakes

Using the Wrong Origin

as.Date(13131, origin = "1970-01-01")

Produces a completely different date than:

as.Date(13131, origin = "1986-01-01")

Always confirm which date system generated the numeric values.

Confusing Days and Seconds

as.Date() assumes the numeric value represents days.

If your value represents seconds, use:

as.POSIXct(
  timestamp,
  origin = "1970-01-01"
)

instead.

Related Functions

Convert Character to Date

as.Date("2025-06-20")

Convert Date-Time Values

as.POSIXct(
  "2025-06-20 10:30:00"
)

Display Structure

str(date_object)

Check Class

class(date_object)

Best Practices

  • Always identify the date origin before conversion.
  • Verify imported dates from Excel or databases.
  • Use str() to inspect data types.
  • Store dates as Date or POSIXct objects whenever possible.
  • Document the origin used in your analysis code.

Conclusion

The error:

Error in as.Date.numeric(X) :
  'origin' must be supplied

occurs because R cannot determine which reference date should be used when converting a numeric value into a Date object.

The solution is simple:

as.Date(13131, origin = "1986-01-01")

By specifying the appropriate origin, R can correctly interpret numeric dates and convert them into meaningful calendar dates.

Understanding date origins is an essential skill for data analysts, statisticians, and data scientists working with imported datasets, Excel files, databases, and time series data.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

two + 12 =