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

as.Date() function for %m/%Y (e.g. 04/2020) format

My df has a date column with month/year dates written like 04/2020. I am trying the as.Date() function to get the right class (because it is a character now) but it only leaves me with NA output. Any help is much appreciated!
Marc-Marijn
  • 151
  • 9
1
vote
1 answer

Why is it that wrapping as.Date() in sapply return a numerical data type, but whereas lapply returns a date data type?

Where I work, the data set that we receive is formatted in character and so needs to be changed to their appropriate data types for any analysis in R. But a weird thing I have noticed is converting the column containing dates from character to dates…
Nitesh
  • 15
  • 1
  • 3
1
vote
1 answer

If else statements for dates in R

Hi I am trying to create a new column in my data frame to say "if 'SightDate' is between 7-15 and 2-15 return TRUE 1 else FALSE [0]" but can't seem to find the syntax for date functions in r. This is what I have so far. #convert SightDate to…
1
vote
1 answer

How to convert a entire column in R character to Date if I use Tibble

I am very new in R. So, I have some difficulties. I have a database in tibble (R language), where my first column is in character so i want to convert to date but I can't. I tried this code: as.Date(x$Date, "%m-%y") But doesn't work. This is an…
1
vote
1 answer

R subset of rows based on comparing two date fields where one is less than

Brand new at R. I have a table of data with two date fields: ReportingPeriodStart Classdate I need two data sets: those rows where ReportingPeriodStart is less than Classdate and one where Reportingperiodstart is greater than Classdate. I thought…
1
vote
1 answer

Converting date to numeric but limiting to number of days in year

I want to create date object between 2008-01-01 and 2010-12-31 around 10K of them. I wrote the code for that but I actually want to keep days 1-366 in 2008 because of 2008-02-29 (leap year) I want them to restart after 366 then become 1 on…
iHermes
  • 314
  • 3
  • 12
1
vote
1 answer

Negative months as difference between two dates

I am aware that there are some posts similar to this here on stackoverflow. But they did not directly address my issue. Here is my issue: I have a variable called earliest_cr_line which contains dates as Jan-01. This is a string variable. I need to…
Anup
  • 239
  • 2
  • 11
1
vote
1 answer

as.Date returns NA if applied to a list

I have want R to recognize this list: [1] "Ago12" "Ago13" "Ago14" "Ago15" "Ago16" "Ago17" "Ago18" [8] "Apr12" "Apr13" "Apr14" "Apr15" "Apr16" "Apr17" "Apr18" [15] "Apr19" "Dic12" "Dic13" "Dic14" "Dic15" "Dic16" "Dic17" [22] "Dic18" "Feb12" "Feb13"…
1
vote
1 answer

Is there an R function for reading a Date in a date_isoweek format?

I have data in a specifc format year_isoweek, e.g., 2019_31 for this week. And I want this represented as a date for further processing. basic r and lubridate; I found some work arounds that have merit, but none of these work with ISO 8601 (%V)…
Markus
  • 169
  • 1
  • 9
1
vote
1 answer

R function to automate adding date column then exporting csv multiple times

I have many csv files that are seperated by day. I wrote a code to manually import each one add a date column and export them again. But this requires me entering hundreds of file names to change the same code over many lines. I want to create a…
1
vote
0 answers

Formatting column as date returns column as "unknown"

I cannot get R to format my column as a date, no matter what I do. I have even gone so far as to create a new string of dates separately and use cbind to add these to the dataframe I want them on, but they are still not recognized as a date. R lists…
Steve G
  • 85
  • 9
1
vote
2 answers

Use lapply on subset of columns with written function?

I have a dataset in which certain columns are dates in character form. The dates are inconsistent in their formatting and missing data are present. I wrote a code to transform them in the correct format. If I use the code for each column with lapply…
MCS
  • 1,071
  • 9
  • 23
1
vote
2 answers

Converting filenames to date in year + weeks returns Error in charToDate (x): character string is not in a standard unambiguous format

For a time series analysis of over 1000 raster in a raster stack I need the date. The data is almost weekly in the structure of the files "... 1981036 .... tif" The zero separates year and week I need something like: "1981-36" but always get the…
FranziM
  • 11
  • 2
1
vote
1 answer

convert date to numeric and back to date

I have some date that I am trying to convert them to numbers and then back to original date. Date 1990-12-31 1991-12-31 1992-12-31 1993-12-31 1994-06-30 1994-12-31 I tried, as.numeric(DF[1:6]) [1] 1 2 3 5 …
YellowRiver
  • 65
  • 1
  • 7
1
vote
1 answer

%b-%Y date conversion gives NA

I am trying to convert character strings to Dates in R. These are examples of the character strings: "Aug-1973" "Aug-1974" "Aug-1975" "Aug-1976" "Aug-1977" I run the following line on date strings similar to the ones above: exportsDF$Date <-…
Michael Berk
  • 705
  • 7
  • 23