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

349 questions
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,782
  • 2
  • 21
  • 39
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
  • 775
  • 1
  • 8
  • 23
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
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
  • 901
  • 4
  • 12
  • 24
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
  • 3,393
  • 3
  • 39
  • 94
2
votes
2 answers

R: assign months to day of the year

Here's my data which has 10 years in one column and 365 day of another year in second column dat <- data.frame(year = rep(1980:1989, each = 365), doy= rep(1:365, times = 10)) I am assuming all years are non-leap years i.e. they have 365 days. I…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
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
0 answers

Specify output of as.Date without the year (R)

I am trying to convert a vector of factors into a vector of dates. The data is formatted as month/date (e.g. 5/20, 4/13, 11/11). I want to retain the format but need to change the data type from factor to date. df$date <- as.Date(df$date, format =…
DPek
  • 180
  • 2
  • 15
2
votes
1 answer

as.Date in R completely changes the years

I have a time-series dataset in csv format. The monthly data is from 4/1/1953 to 6/1/2017. I want to convert this into an xts object in R. I used the following codes to import the dataset and then convert into xts. However, after the conversion, my…
Anup
  • 239
  • 2
  • 11
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"…
ankit agarwal
  • 51
  • 1
  • 4
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
  • 347
  • 2
  • 14
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
  • 123
  • 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…
WhatAmIDoing
  • 198
  • 1
  • 1
  • 6
1
vote
4 answers

convert 'yyyy-mm-dd' to month-year format and make a sequence in r

I want to make a Date sequence from 2010-04-01 to 2040-03-01, and express the date format to be "April-2010", or "Apr 2010". However, when I used as.yearmon() it only returned "4 2010" instead of "Apr 2010". This is my first code which I tried to…