Fixing R Errors: error in as.date.numeric(value) : ‘origin’ must be supplied

Error messages are an unfortunate part of programming but do not be too concerned when you get them. They are a natural result of programming, particularly as your problems become more complex. The “Error in as.date.numeric(value) : ‘origin’ must be supplied” error message occurs when converting a numeric value into a date. It is a result of omitting a component from the function.

The circumstances of this error.

This error message occurs when using a numeric value with the as.Date() function. The message clearly indicates that it is missing the starting date the functional will use.

> a = read.table(text = ‘
+ Number date
+ 13020 May-25-1996
+ 14990 Oct-16-2001
+ 14776 Mar-16-2001
+ 15140 Mar-15-2002
+ 15974 Jun-15-2004′, header=TRUE)
> as.Date(a$Number)
Error in as.Date.numeric(a$Number) : ‘origin’ must be supplied

In this example, we have numbers and the date they are pointing to. The error message tells you exactly what is wrong. The term “‘origin’ must be supplied” means that you have not given the as.Date() function a starting date. This an easy oversight, particularly when you are new to this function.

What is causing this error?

What is causing this error message is the fact that the numeric value you are entering into the as.Date() function counts that number of days from a starting date

> a = read.table(text = ‘
+ Number date
+ 13020 May-25-1996
+ 14990 Oct-16-2001
+ 14776 Mar-16-2001
+ 15140 Mar-15-2002
+ 15974 Jun-15-2004′, header=TRUE)
> as.Date(a$Number, origin = “1964-10-22”)
[1] “2000-06-15” “2005-11-06” “2005-04-06” “2006-04-05” “2008-07-17”

This code works because it provides a starting date from which the numeric values you are using can calculate the date it counts too. If that starting date is not present, the formula has no place to start its calculations causing it to produce an error message. It is an easy error message to understand and just as easy to correct.

How to fix this error.

Fixing this error message is a simple matter of adding the needed starting date. When you are using a number with a starting date the proper format of the as.Date() function is as.Date(number, origin = “yyyy-mm-dd”) in the format of the started date is important to the function working properly.

> as.Date(a$Number)
> as.Date(a$Number, origin = “1964-10-22”)

A comparison of the as.Date() function from both examples, clearly shows how to fix this error. All you need to do is add an origin date and you will have this problem fixed. It is just that easy. Now, it is possible, your mistake could actually be elsewhere, such as in the formatting of a data structure. However, if you are getting this error message, this fix is the first place to start.

Scroll to top
Privacy Policy