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
2
votes
1 answer

`as.Date()` identifies years in short form(say 01/10/68) as `2068-10-01` instead of `1968-10-01`, how to fix it?

I have a csv dataset that has date of births stored as characters in the format - 01-06-68("%d-%m-%y"). I tried to convert the dates to Date objects using as.Date() but it identifies the year as 2068 when in fact the year is 1968. I understand Date…
Alan
  • 21
  • 3
2
votes
1 answer

Convert date with 'May' to number format doesn't work in R

I am wondering why the following works as.Date("07Jan2013", "%d%B%Y") "2013-01-07" but, this doesn't as.Date("07May2013", "%d%B%Y") NA Only the month May gives this issue.
milan
  • 4,106
  • 1
  • 17
  • 32
2
votes
0 answers

vapply and FUN.VALUE for non-primitive data types

Will vapply work with data classes beyond numeric, character, and logical? Can vapply return as.Date data in the original class? Here's my list: name <- "Truman" birth <- as.Date("1884/05/08") death <- as.Date("1972/12/26") no33 <- …
Mark R
  • 588
  • 4
  • 18
2
votes
2 answers

Convert dates from Stata to R

I am having difficulty converting a vector of integers into dates. I've imported a dataset from Stata using: > dataire <- read.dta13("~/lcapm_ireland.dta", convert.factors = TRUE, generate.factors = FALSE, encoding = "UTF-8", fromEncoding = NULL,…
2
votes
1 answer

No way to solve as.Date returning NA

R Studio beginner here. I am trying to turn a character into a date through as.Date. My code is like this: date=c("23-Nov-1994") date <- as.Date(date, format="%Y%m%d") but it returns NA. I also tried as.POSIXlt("23-11-1994",…
Valentina Ruts
  • 101
  • 1
  • 6
2
votes
2 answers

How to apply as.Date function in multi column without knowing the index R

Desire to convert class of multi cols without knowing the location . This is the dataset # Dataset name call : df . # It is a example , real data has many columns # that you cannot have a clear index by one sight. A.Date Price B.Date …
rane
  • 769
  • 1
  • 7
  • 19
2
votes
1 answer

Convert day of year to date assuming all years are non-leap years

I have a df with year and day of year as columns: dat <- data.frame(year = rep(1980:2015, each = 365), day = rep(1:365,times = 36)) Please note that I am assuming 365 days in a year even if it is a leap year. I need to generate two things: 1)…
89_Simple
  • 2,829
  • 2
  • 23
  • 67
2
votes
2 answers

error message: do not know how to convert 'dataFrame$col' to class “Date”

I have a data frame with records from the month of October 2017. Column 6 has the dates as a character vector. This is what it looks like: > october2017[1:6,1:6] V1 V2 V3 V4 V5 V6 1 89108060 IN0000005 P2 RK1 CA1-R…
Jennifer B.
  • 121
  • 1
  • 2
  • 10
2
votes
0 answers

sapply to POSIXct vector returns wrong values?

The codes and results shown below: (p <- as.POSIXct(c("2017-09-21 UTC", "2017-09-22 UTC"))) [1] "2017-09-21 PDT" "2017-09-22 PDT" as.Date(p) [1] "2017-09-21" "2017-09-22" (d <- sapply(p, as.Date)) [1] 17430 17431 Why the sapply returns a numeric…
A-L
  • 41
  • 2
2
votes
3 answers

as.Date with two-digit years

If I convert the date 10.10.61 (DD.MM.YY) with as.Date(date, format="%d.%m.%y") for some reason it converts it into 2061-10-10. Is there an elegant way to correct for this or do I have to do it manually by slicing the string and adding "19" in…
D. Studer
  • 875
  • 8
  • 20
2
votes
2 answers

as.Date function, 'format' argument

I am trying to convert charater string to date class value with as.Date function. The character string that I’m working on looks like below: [1] "Sep 1, 2016" "Aug 31, 2016" "Aug 30, 2016" "Aug 29, 2016" "Aug 26, 2016" [6] "Aug 25, 2016" "Aug 24,…
송병채
  • 21
  • 2
2
votes
0 answers

Character to date format conversion

x <- c("1-jan-60", "2-jan-89", "31-mar-89", "30-jul-93") z <- as.Date(x, "%d-%b-%y") z "2060-01-01" "1989-01-02" "1989-03-31" "1993-07-30" I converted character date into date format it is giving as wrong output. the output should be "1960-01-01"…
2
votes
3 answers

as.Date returns different formats if sapply or not

I have a data frame with a date columns that I need to convert into a format R recognizes as a date. > dataframe Date Sum 1 06/09/15 2.51 2 06/09/15 3.75 3 06/09/15 3.50 ... I first converted it using…
Unrelated
  • 257
  • 1
  • 11
2
votes
1 answer

Dates on x-axis, time series

I have data covering a time period of over 25 years and I would like to see the years on the x-axis. dates <- as.Date(Dollar[,1], "%d.%m.%Y") Dollar <- as.xts(Dollar[,2], dates) plot(SWEDOLall, xaxt = "n", main="SMA", ann = FALSE) axis.Date(side =…
Jule
  • 113
  • 9
2
votes
2 answers

convert year week string to date

I have a column of strings in my data set formatted as year week (e.g. '201401' is equivalent to 7th April 2014, or the first fiscal week of the year) I am trying to convert these to a proper date so I can manipulate them later, however I always…
Youcef Kadri
  • 113
  • 1
  • 1
  • 6
1 2
3
19 20