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
4
votes
4 answers

Using the "format" argument in as.Date()

I'm trying to convert "07,29,30" into a Date format using as.Date() in R. (Note that the format of the string is "mm,dd,yy", being July 29, 1930) So I used the following code: as.Date("07,29,30", format = "%m,%d,%y") But the year that I get…
4
votes
2 answers

R Convert to date from multiple formats

I need to convert a string of dates that is in multiple formats to valid dates. e.g. dates <- c("01-01-2017","02-01-2017","12-01-2016","20160901","20161001", "20161101") > as.Date(dates, format=c("%m-%d-%Y","%Y%m%d")) [1] "2017-01-01" NA …
user3357059
  • 976
  • 11
  • 25
4
votes
1 answer

R POSIXct and as.Date

I have a date and time value which I'm using POSIXct to store in a variable. and when I use as.Date the date is different - why ? x<-as.POSIXct("2012-02-25 19:00:00") as.Date(x) [1] "2012-02-**26**" Why is it incrementing day by 1?
Sri
  • 970
  • 1
  • 14
  • 26
4
votes
0 answers

as.Date dosen't work with %d-%b-%y (R)

I'm trying to convert dates in R from "1-Apr-02" to "2002-04-01", but as.Date does not recognise the format: > as.Date("1-Apr-02", format="%d-%b-%y") [1] NA Even if I put a "01" instead of "1", it doesn't work.
allmy
  • 54
  • 3
3
votes
3 answers

Converting yearly data into xts format

I have a very beginners question. I would like to work with the time series package xts. Therefore, to convert my data to xts format. My current dataset "data" is a "data.table" "data.frame" format. The Year column is an "integer". The filtered…
Mels
  • 57
  • 5
3
votes
3 answers

Use as.Date with tryFormats to parse dates with different formats

I have a variable with dates in a two different formats ("%Y-%m-%d" and "%m/%d/%Y"): dput(df) structure(1:8, .Label = c("2019-04-07", "2019-04-08", "2019-04-09", "2019-04-10", "7/29/2019", "7/30/2019", "7/31/2019", "8/1/2019" ), class =…
NoobR
  • 191
  • 9
3
votes
2 answers

paste function in r

I would think this should be an extremely easy solve; but, I can't find it on here; and, the instructions that I've found elsewhere haven't worked. All I'm trying to do is use a simple paste function. In my data frame, I have a date variable…
3
votes
1 answer

R - How can I change date format when I plot an xts & zoo object?

I am wondering how I can change date format. The code I am working on is following: library(quantmod) getSymbols("AAPL") price_AAPL <- AAPL[,6] plot(price_AAPL, main = "The price of AAPL") This results I want to alter date format from "%m %d…
Louis
  • 43
  • 5
3
votes
2 answers

Generate a sequence of the same weeks every month in R

I'm trying to generate a sequence of weeks which repeat itself for every month. I've created the sequence for one month obviously, but I'd like that sequence to be the same for every month also. sequence2 <- format(seq(as.Date("2004-01-01"),…
3
votes
1 answer

Continuous week transition over years

I'm trying to calculate week offset using as.Date with respect to any origin or base date. E.g.: bd = as.Date("2013-12-29") ad1 = as.Date("2014-01-01") ad1w = as.numeric(strftime(ad1, format = "%W")) ad2 = as.Date("2015-04-20") ad2w =…
Alexey Ferapontov
  • 4,529
  • 4
  • 18
  • 36
3
votes
2 answers

R: Wrong converting ISO-Week to Date

I've got a year, an ISO-Week and a weekday (year 2015, week 7, weekday 1 == 2015-02-09) and I'd like to convert it to the date. So I do it the following way: date <- "2015:7:1" as.Date(date, format="%Y:%V:%u") [1] "2015-03-25" As you can see I get…
JerryWho
  • 2,750
  • 3
  • 23
  • 47
2
votes
2 answers

Format x-axis date in chr type on facet_wrap using R

*** Updated code so it is reproducible. *** This question relates to R using RStudio. I need to format the date on the x-axis as three-letter month and two-digit day, as shown below (Mar 01). The date is a dataframe itself as date.local, it's of…
Fher
  • 35
  • 4
2
votes
0 answers

Preserve %d-%b-%Y as Date rather than character in R tibble

Suppose I look at the date March 5th: > temp <- as.Date("05-Mar-2021", "%d-%b-%Y") > temp [1] "2021-03-05" > tibble(temp) # A tibble: 1 x 1 temp 1 2021-03-05 Note that the tibble correctly says it's a date. Now I want a…
user1357015
  • 9,314
  • 16
  • 56
  • 100
2
votes
0 answers

App on Shinyapp io server doesn't display latest dates in table but on local computer it works

I have recently built an app and loaded it to shinyapps io. There I can see my app with all its tabs, tables and functions. In my app I have a table in each tab. With each table the user can select a range for the dates of what is to be shown in the…
Nick
  • 77
  • 1
  • 1
  • 11
2
votes
3 answers

Converting factor into dates for boxplot in R unsuccessful with "st" "nd" "rd" "th" added to dates

The dataset I have contains the following list of dates that are currently being recognised as factors: Interview_Date = c("Monday 23rd May 2005", "Tuesday 24th May 2005", "Wednesday 25th May 2005", "Thursday 26th May 2005", …
1
2
3
19 20