This question already has an answer here:
Trouble with date format using the function as.POSIXct in R
(1 answer)
Closed 8 years ago.
I have a data frame with RFC 3339 format ("2012-04-12T19:02:32Z") and I need to turn into a date type R, I found as.POSIXct function but can not use it properly.
Try this:
R> as.POSIXct("2012-04-12T19:02:32Z", format="%Y-%m-%dT%H:%M:%SZ")
[1] "2012-04-12 19:02:32 CDT"
R>
The arguments for the format string are detailed in the help page.
Related
This question already has answers here:
Convert quarter/year format to a date
(1 answer)
Convert character field to quarter date in R
(3 answers)
Closed 2 years ago.
I would like to turn a character variable formatted as YYYY-QQ, so for example 2010-Q1, into something I can use as a date. I have played around with as.yearqtr, but haven't could only figure out the output format. I haven't been been able to define the input format though.
Edit:
Has also been answered here.
You have to use the right format in as.yearqtr formula like this:
library(zoo)
x<-"2010-Q1"
as.yearqtr(x, format = "%Y-Q%q")
[1] "2010 Q1"
This question already has an answer here:
converting datetime string to POSIXct date/time format in R
(1 answer)
Closed 2 years ago.
Using R, how do I transform the date and time from here, into a "standard" date/time string format?
2020-12-30T03:32:30.000Z
Use ?strptime
strptime("2020-12-30T03:32:30.000Z", "%Y-%m-%dT%H:%M:%S")
# [1] "2020-12-30 03:32:30 CET"
You can also use:
#Code
as.POSIXct(gsub('T|Z',' ','2020-12-30T03:32:30.000Z'),'%Y-%m-%d %H:%M:%S.%OS')
Output:
[1] "2020-12-30 03:32:30 GMT"
This question already has answers here:
How to convert Excel date format to proper date in R
(5 answers)
Closed 2 years ago.
I want to convert numeric date format to date. I.E. I have value 44109, but want to convert it to 2020-10-06. How is it possible?
Try something like below
> as.Date(44109,origin = "1900-01-01")
[1] "2020-10-07"
this works as well
x <- as.POSIXct(44109 * (60*60*24), origin="1899-12-30", tz="GMT")
"2020-10-05 GMT"
This question already has answers here:
Converting to date in a character column that contains two date formats
(4 answers)
Closed 5 years ago.
I have various data sources and each data source has a different convention on naming dates.
Example:
Some are:
May 16,2017 as Character type
While others are:
16/05/2017 as Date type
Is it possible to write a code that would coerce everything including those in character to dd/mm/yyyy date format?
We could use the parse_date_time from lubridate which takes multiple formats
library(lubridate)
parse_date_time(str1, c("mdy", "dmy"))
#[1] "2017-05-16 UTC" "2017-05-16 UTC"
data
str1 <- c("May 16,2017", "16/05/2017")
This question already has answers here:
Convert numeric to date
(2 answers)
Closed 6 years ago.
I'm working with hundreds of stores data with R.
And there is store open data.
But it's unarranged, for example "20061019".
I'd like to convert into "YYYY-MM-DD" format.
Plz teach me how to deal with it. thx :)
paste(substr(aa,1,4),"")
[1] "2006 " "2016 "
paste0(substr(aa,1,4),"-",substr(aa,5,6),"-",substr(aa,7,8))
[1] "2006-10-19" "2016-09-09"
We can use as.Date with format argument (from base R)
as.Date("20061019", format = "%Y%m%d")
#[1] "2006-10-19"
One of the ways you can do this is with lubridate ymd function like this
library(lubridate)
ymd("20061019")