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
2 answers

Extract year YYYY from date DD.MM.YYYY as new variable in R

I have a field (variable) data2$DatumZalozenia with dates as follows 06.12.2013. Format of the values in the variable is DD.MM.YYYY. The variable is type chr. I need to extract the year out of the date and create new variable data2$RokZalozenia in a…
1
vote
1 answer

in R, why does as.Date(Inf) display as NA, yet fails the test for being NA

An alternative title to this question is: When is an NA date not an NA? Answer: when it is infinity formatted as a date. Converting infinity to a date results in NA being displayed, but it is not! > BadDates <- as.Date(c(NA,Inf,-Inf)) > BadDates [1]…
Rainfall.NZ
  • 197
  • 1
  • 12
1
vote
2 answers

R function from string cell YEARMonth as date?

So I have this long dataset, where in one column I have a date specified as character in format YYYMMM, but month abbreviated. So for example 1995MAR, 1995APR and so on. How can I transform that to date format? I tried as.Date but it obviously…
matfan
  • 11
  • 1
1
vote
2 answers

How to remove duplicate values per day in r?

I've a simple question but I couldn't find a plausible solution. My dataframe looks like this: dput(prec) structure(list(date = structure(c(19091, 19091, 19092, 19092, 19093, 19093, 19094, 19094, 19095, 19095, 19096, 19096, 19097, 19097, 19098,…
Cláudio Siva
  • 502
  • 2
  • 10
1
vote
1 answer

My Ggplots are formatting the date incorrectly (sorting by year when in the format %m/%y)

countrydf$dates <- format(as.Date(countrydf$date, format="%Y-%m-%d"), "%m/%y", ordered = T) germanydf <- subset(countrydf,location == "Germany") ggplot(germanydf, aes(x=dates, y=total_deaths)) + geom_bar(aes(), stat = 'identity', position =…
1
vote
2 answers

Using column index to drop row, rather than being reliant on name

I've got a dataframe of the following pattern: tibble [9 x 2] (S3: tbl_df/tbl/data.frame) $ Date: chr [1:9] "Tuesday 4 October 2022" "Wednesday 5 October 2022" "Thursday 6 October 2022" "Note that:" $ EVENTS CALENDAR : chr [1:9] "A61" "A32"…
alec22
  • 735
  • 2
  • 12
1
vote
1 answer

Convert character in format YEARQT to a quarterly "date" in R

Date 1960Q1 1960Q2 1960Q3 1960Q4 1961Q1 1961Q2 I have the following data.frame. I am trying to put this first column into a tsibble. Now I have a problem. How can I switch to a date so that it can be read as a quarter. I tried…
C. Master
  • 113
  • 4
1
vote
2 answers

Select data based on a day in a month, "If date is lesser than a day in a month"

I have a dataset with a column date like this : id date 1 2018-02-13 2 2019-02-28 3 2014-01-23 4 2021-10-28 5 2022-01-23 6 2019-09-28 I want to select data that have a date lesser than 15th February I tried an ifelse statement…
Othmane
  • 33
  • 4
1
vote
1 answer

Create a vector of years and weeks with ISO-8601 format in R

I would like to create a vector from one date to another displayed as YYYYWW which increments by week. It is important that the weeks are displayed in ISO-8601 standard format, here is a link for reference to the ISO-8601:…
chilifan
  • 157
  • 1
  • 12
1
vote
2 answers

Change Date format - Convert to Date Class

I have a column of dates that were read in as character. I want to produce a data class with my desired format (say, US-style, 08/28/2020). But, all solutions to change format, produce character class, or produce date class with standard format…
1
vote
2 answers

The wrong language when extracting date from datetime using as.Date function

I extract date using this piece of code : all_trips$day_of_week <- format(as.Date(all_trips$date), "%A") I get days of the week in Russian language (I'm using Windows 10 and it's also in Russian),but I'd like to get them in English since everything…
Mohmad
  • 31
  • 4
1
vote
1 answer

How to simplify the filter code for given days

When filter some days value from dataframe, I have to repeat 'as.Date' many times in filter condition sentence. Is there any way to simplify it? Thanks! library(tidyverse) test_data <- data.frame(mday=seq.Date(as.Date('2021-1-1'), …
anderwyang
  • 1,801
  • 4
  • 18
1
vote
3 answers

Add date points between separate dates in a dataframe and create blanks (NA) in the other columns were those newly rows were created in r

This is how my data looks like: > dput(head(h01_NDVI_specveg_data_spectra,6)) structure(list(ID = c("h01", "h01", "h01", "h01", "h01", "h01" ), collection_date = structure(c(15076, 15092, 15125, 15139, 15159, 15170), class = "Date"), NDVI =…
Cláudio Siva
  • 502
  • 2
  • 10
1
vote
3 answers

How to convert a "char" column to datetime column in large datasets

I am working with large datasets and in which one column is represented as char data type instead of a DateTime datatype. I trying it convert but I am unable to convert it. Could you please suggest any suggestions for this problem? it would be very…
Nikhil
  • 61
  • 6
1
vote
3 answers

Reformatting dates in multiple columns at once in R

I am trying to convert multiple columns from "character" to date, but also reformat the date. I can do it column by column, but am hoping to write some sort of loop to iterate over all the variables. For example, I can do dates_test$date.d.m.y <-…