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
1
vote
3 answers

R lubridate. What goes wrong?

Tried to make a factor to date. X: Jul-15 Jul-15 Jul-15 Jul-15 Aug-16 I want to convert them to a date. X <- as.Date(Xx, format="%b-%y") Results in NA's. This was my source for the code: https://www.r-bloggers.com/date-formats-in-r/
user5947793
1
vote
2 answers

Plotting dates in 3D plots R

I am trying to plot date, x and y in a 3D plot in R. (Using RStudio 0.99.903), R (3.3.2), scatterplot3d(0.3-40), rgl(0.98.1) dates = c("2016-11-10","2016-11-20","2016-12-01","2016-12-15","2016-12-30") x = rnorm(5,0,1) y = rnorm(5,1,2) A =…
Susan
  • 11
  • 3
1
vote
2 answers

function as.Date just recognizes german month - but not english month

I need to transform dates in R which have the format e.g. "01OCT2011". The Problem is that the function as.Date only considers German months. Here, I have an example: > test <- c("15MAI2006","01OCT2011") > test1 <- as.Date(test, format='%d%B%Y') >…
I.AH
  • 27
  • 1
  • 7
1
vote
1 answer

Dates are not keeping specified format in R data frame

Simply put, I'm grabbing dates for events that meet certain conditions in df1 and putting them in a new data frame (df2). The formatting of dates in df2 should be the same formatting in df1 ("2000-09-12", or %Y-%m-%d). However, the dates in df2…
Kirsten
  • 31
  • 3
1
vote
1 answer

Applying as.Date returns NA

I have vector of dates that looks like this (in reality the vector is much longer): dta= data.frame(c("Mar 22, 2013", "Feb 4, 2013","Oct 3, 2016", "Apr 8, 2014", "Sep 6, 2013", "Jul 16, 2014")) colnames(dta)<-c("time") dta$time<-as.Date(dta$time,…
Jannis
  • 47
  • 5
1
vote
1 answer

Count people present within specified date range

I have one df containing individuals' arrival & departure dates and their total length of stay (los): arrive <- as.Date(c("2016/08/01","2016/08/03","2016/08/03","2016/08/04")) depart <- as.Date(c("2016/08/02","2016/08/07","2016/08/04",…
jesstme
  • 604
  • 2
  • 10
  • 25
1
vote
1 answer

Using as.Date and grep to format inconsistent dates in one vector

I'm fairly new to R, but I've had a great deal of challenge doing what otherwise seems like a simple task. I have a number of inconsistently recorded dates in one vector. My goal is to convert them all to the same R accepted date format in a new…
CConroy
  • 11
  • 2
1
vote
1 answer

Dates format in R: 3/31/2016 io 03/31/2016

Is there a way to have the dates in R as 3/31/2016 (not showing 03 for the month)? Right now my code is: dates <- seq(as.Date("2000-1-1"), as.Date("2016-10-1"), by="3 months") -1 dates <- format(dates, format = "%m/%d/%Y") But the outcome is [1]…
lapioche75
  • 87
  • 1
  • 2
  • 9
1
vote
2 answers

creating a loop to convert rolling date periods to as.Date

I'm new to R, but have been following a pretty good guide to help along the way. I've imported sales data for the past 36 months, used tidyr to move the Date columns to rows, and then cleaned the Date character string to a Month Date, Year. My ask…
Sherif B
  • 11
  • 3
1
vote
0 answers

Convert numeric to date by month since 1800-01-01?

I have ncdf file that can be download here. This dataset contains two variables (TA and DMI). TA value represents the date with unit MONTHS since 1800-01-01 00:00:00. How to convert the TA value into date (as.Date)? Here my…
Eko Susilo
  • 250
  • 2
  • 15
1
vote
3 answers

Parse string with additional characters in format to Date

I have a string variable that I want to parse to class Date. In addition to the day, year and month, the format has other characters like separators (, ), letters and apostrophes (u''), like this: "u'9', u'2005', u'06'" I have…
Zlo
  • 1,150
  • 2
  • 18
  • 38
1
vote
2 answers

Why applying as.Date() on "general" formatted excel variables can't work?

I was reading in a .csv file into R, where the .csv file was originally saved in Excel format. While preparing for the .csv file, i did a copy and paste of the content on a new spreadsheet, and the Date.Sold variable was formatted as "general" in…
hagewhy
  • 79
  • 1
  • 1
  • 6
1
vote
1 answer

as.Date command in R returns NA

My date variable keeps returning a "NA" when i use the as.Date() command. I have practically tried all the various ways, which include (a) stating the origin argument; (b) setting the locale (c) converting the original variable into characters…
hagewhy
  • 79
  • 1
  • 1
  • 6
1
vote
1 answer

Change datatype from factor to date

I have a dataset with dates. Class(dataset) returns "factor" Now I want to transform it into a dataset with dates. I use the as.Date function: as.Date(dataset, format = "%Y/%m/%d") Now things gets weird. My data disappear. The dataset now…
1
vote
1 answer

r as.Date returns previous day

as.Date(date1) is incorrectly returning the previous day. I suspect it has got to do with time zones, but I am still learning the very basics of R so I have little chance of solving it on my own. The code I use to produce this is: > a <-…
gmarais
  • 1,801
  • 4
  • 16
  • 32