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

Convert correct date format in R

It is what my row data looks like: Extraction BORN 1 30/06/06 31/01/48 2 30/06/06 20/05/74 3 30/06/06 20/02/49 4 30/06/06 06/07/53 5 30/06/06 26/05/63 6 …
Amber Tseng
  • 65
  • 2
  • 8
1
vote
1 answer

Trouble with as.Date

I currently have date data in the following format: DDMMYYYY I want to convert the dates to proper date function (I suspect I will need to for visualizing the temporal data) using the following: data$DATE<-as.Date(as.character(data$DATE),…
1
vote
3 answers

Convert a string to Date by as.Date function

I have my string formatted as: 20170814 and wanted to convert to date by as.Date function but keep producing me 'NA". This is my function: a<-"20170814" as.Date(a,"%y-%m/%d") Can you please give me some help Thanks
hn.phuong
  • 835
  • 6
  • 15
  • 24
1
vote
1 answer

Generate which 15-days period a day fall into

I have a data frame with year and day df <- data.frame(year = rep(1980:2015,each = 365), day = 1:365) Please note that I only need 365 days a year i.e. I am asusming each day has 365 years. I want to generate two data: 1) which month does each…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
1
vote
1 answer

How to use as.Date if there is NA, empty cells, and different formats within the same column?

Inside my data frame, a column consists of two kinds of date formats (%Y-%m-%d and %d/%m/%Y), empty cells, and NA. The following method is my attempt which did not produce the desired outcome. I tried to convert them as follow.... a <-…
Teddy
  • 11
  • 1
  • 3
1
vote
1 answer

Error in changing data into Date in [R]

I have a problem in converting a vector into date one by using as.Date. Data is as below. > new3<-read.csv("Total Load - Day Ahead _ Actual.csv",stringsAsFactors=F) > colnames(new3)<- c("Date","Hour","Dayahead","Actual") > str(new3) 'data.frame': …
junmouse
  • 155
  • 1
  • 9
1
vote
1 answer

Issue with R ddate format "%Y-%V"

I don't understand the following behaviour: format(as.Date("2017-01-01"), "%Y-%V") [1] "2017-52" > as.Date("2017-01-01") [1] "2017-01-01" > format(as.Date("2017-01-01")-1, "%Y-%V") [1] "2016-52" I was expecting, as output of first row, to get…
YCR
  • 3,794
  • 3
  • 25
  • 29
1
vote
0 answers

Strange behavior with as.Date in base R

I have created two variables that represent the min and max of yesterday's time: yesterday_min <- force_tz(as.POSIXct(sprintf('%s 00:00:00', Sys.Date()-1)), 'America/New_York') yesterday_max <- force_tz(as.POSIXct(sprintf('%s 00:00:00',…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
1
vote
2 answers

Create a plot with time on the x- and y-axis (in R)

There are two points in time (two measurements), I would like to plot the first time on the x-axis and the second on the y-axis as points, hence I could easily inspect data-points above the 45°-line for which the second measurement is after the…
Marco
  • 2,368
  • 6
  • 22
  • 48
1
vote
1 answer

Change date saved as Character to Date

Guys I've been trying to change dates given in character form to a date , but I keep getting the wrong answers or an error. This is the structure of my data: Classes ‘data.table’ and 'data.frame': 2880 obs. of 9 variables: $ Date : chr "1/2/2007"…
1
vote
1 answer

as.Date conversion returns NA

I am using this data. When I want to define the variable as.Date() I am getting NA. This is the code I am using. Can someone please advise what I am doing wrong? dataf <- read.csv("DB.csv") dataf$Date <- as.Date(dataf$Date, format =…
Tamra.y
  • 235
  • 3
  • 9
1
vote
1 answer

How do I get better date breaks on the x-axis of a scatterlot?

I have got a data frame like this: Days Ahm5 01/06/1961 0.00000 02/06/1961 0.19266 03/06/1961 1.67610 ........ ........ 30/09/1961 5.26514 01/06/1962 0.05200 ......... ........ 30/09/2007 0.866473 Here's the…
ajilesh
  • 299
  • 3
  • 13
1
vote
1 answer

Convert first date of the month to yearmon in R

I have been trying to get the year month as a new column to my following example data set. time site 1 1/01/2000 A 2 1/02/2000 A 3 1/03/2000 A 4 1/04/2000 A 5 1/05/2000 A 6 1/06/2000 A 7 1/07/2000 A 8 1/08/2000 …
sriya
  • 179
  • 1
  • 2
  • 7
1
vote
0 answers

Generate quarters within start date and end date and calculate how many days fall within each quarter

I am quite new to R and have a question, hopefully someone will know the answer. I have a (small sample) dataset which looks like this: structure(list(ID = 1:6, Date_Start = structure(c(7305, 7702, 12114, 9714, 11819, 8418), class = "Date"),…
Robbert
  • 11
  • 2
1
vote
2 answers

Character format cannot change to Date format

I have a data and there is a column called Date, I input the data into R. Here is my data: unique(data$Date) [1] "" "2016/12/20" "2016/12/27" "2017/1/7" "2017/1/27" "2017/2/1" "2017/2/2" "2017/2/5" "2017/2/6" "2017/2/7" …
Peter Chen
  • 1,464
  • 3
  • 21
  • 48