Questions tagged [as.date]

as.Date is an R function used to convert between character or numeric representations and objects of class "Date", representing calendar dates.

as.Date is an R function used to convert between character or numeric representations and objects of class "Date", representing calendar dates.

https://www.rdocumentation.org/packages/base/versions/3.3.2/topics/as.Date

289 questions
98
votes
5 answers

What are the "standard unambiguous date" formats for string-to-date conversion in R?

Please consider the following $ R --vanilla > as.Date("01 Jan 2000") Error in charToDate(x) : character string is not in a standard unambiguous format But that date clearly is in a standard unambiguous format. Why the error message? Worse, an…
Matt Dowle
  • 56,107
  • 20
  • 160
  • 217
41
votes
3 answers

Convert character to class Date

I have a data frame with a character column of dates. When I use as.Date, most of my dates are parsed correctly, except for a few instances. The example below will hopefully show you what is going on. # my attempt to parse the string to Date --…
Btibert3
  • 34,187
  • 40
  • 119
  • 164
21
votes
5 answers

Convert week number to date

I have a data frame in R with the week of the year that I would like to convert to a date. I know I have to pick a year and a day of the week so I am fixing those values at 2014 and 1. Converting this to a date seems simple:…
Aaron Soderstrom
  • 469
  • 1
  • 5
  • 11
20
votes
2 answers

How to avoid date formatted values getting converted to numeric when assigned to a matrix or data frame?

I have run into an issue I do not understand, and I have not been able to find an answer to this issue on this website (I keep running into answers about how to convert dates to numeric or vice versa, but that is exactly what I do not want to…
Joes de Natris
  • 303
  • 1
  • 2
  • 5
19
votes
2 answers

Fastest way to parse a date-time string to class Date

I have a column with dates as character in the format 10/17/2017 12:00:00 AM. I want parse the string and keep only the date part as class Date, i.e. 2017-10-17. I am using - df$ReportDate = as.Date(df$ReportDate, format = "%m/%d/%Y %I:%M:%S %p")…
phil_t
  • 821
  • 1
  • 7
  • 16
9
votes
3 answers

as.Date produces unexpected result in a sequence of week-based dates

I am working on the transformation of week based dates to month based dates. When checking my work, I found the following problem in my data which is the result of a simple call to as.Date() as.Date("2016-50-4", format =…
KoenV
  • 3,428
  • 2
  • 16
  • 27
8
votes
4 answers

R set default origin for as.Date

Is there a way to set default origin for as.Date? I did this function to workaround: as.date=function(x, origin='1970-01-01') as.Date(x, origin=origin) For example: as.Date(0) Error in as.Date.numeric(0) : 'origin' deve ser…
xm1
  • 1,107
  • 1
  • 11
  • 22
8
votes
1 answer

R: Setting limits to scale_x_yearqtr in ggplot for yearqtr (zoo)

I'm working with the data set resembling the extract below: head(nomis.lng.agg) quarter decile avg.val 1 2004 Q4 1 5.680000 2 2005 Q1 1 5.745763 3 2005 Q2 1 5.503341 4 2005 Q3 1…
Konrad
  • 14,406
  • 15
  • 86
  • 141
7
votes
4 answers

as.Date from 'YYYY.mm' format

I have a data frame where date is stored as a double e.g., 1993.09 1993.10 1993.11 1993.12 I want to convert this into a date format '%Y %m %d' (with days always 1). As far as I understand, as.Date() wants a string input. However, for some reason…
Zlo
  • 1,056
  • 1
  • 14
  • 34
7
votes
2 answers

R Read abbreviated month form a date that is not in English

I have a text file that includes dates, and want to convert it to a datatable. Converting the dates such as 03-FEB-2011 can be done with data$fecha <- as.Date(data$textDate , "%d-%b-%Y") The problem is that the column is in Spanish, so I don't get…
Maria Velasco
  • 171
  • 1
  • 3
  • 8
7
votes
2 answers

R script working locally not working on shinyapp.io

I'm trying to put together a R + Shiny app that, at least initially, plots a histogram of date data. I have it working just fine on my local system in RStudio, but in shinyapps.io it doesn't work. The app, at the moment, is very simple - the…
Nik T
  • 73
  • 4
5
votes
1 answer

Setting xlim with dates in R

I need to set the x-axis limit of a plot in R, but my values are dates (%m/%d/%Y format). How would I go about changing this? I am trying to plot trophic position vs. collection date. All of my collection dates are in date format (%m/%d/%Y) This is…
M. Bittner
  • 51
  • 1
  • 1
  • 2
5
votes
2 answers

How to extract correct date from POSIXct element?

How can I get the correct date from the first column in my code? test <- data.frame(posixdate = c("2013-05-01 00:59:00", "2013-05-01 01:59:00", "2013-05-01 02:59:00", "2013-05-01 03:59:00")) test$posixdate <- as.POSIXct(test$posixdate,…
Aki
  • 379
  • 1
  • 5
  • 15
5
votes
2 answers

How to handle blank items when converting dates in R

I have a csv download of data from a Management Information system. There are some variables which are dates and are written in the csv as strings of the format "2012/11/16 00:00:00". After reading in the csv file, I convert the date variables into…
Tyler Durden
  • 193
  • 2
  • 12
4
votes
1 answer

Convert week number to date keeps adding week number to today's date

Sorry, this has been asked multiple times but none of the posted replies have worked for me. I am trying to convert week number to date or ideally a month name using as.Date function. However I keep getting the same result no matter what week I put…
1
2 3
19 20