problem with dates in r studio

0

I have a CSV file with this data

DATE,IUMABEDR
31 Jan 1975,11.3295
28 Feb 1975,10.6875
31 Mar 1975,10.2632
30 Apr 1975,9.9091
31 May 1975,9.9762
30 Jun 1975,10
31 Jul 1975,10.1739
31 Aug 1975,11
30 Sep 1975,11
31 Oct 1975,11.8696
30 Nov 1975,11.875
31 Dec 1975,11.4643
31 Jan 1976,10.8333
29 Feb 1976,9.625
31 Mar 1976,9.0543

I can read it with the code:

stuckey <- read.csv("resultsinteresrates.csv", header=TRUE, sep=",", dec=".")

But when trying to change the date from str to date with codes like this one among others:

stuckey$DATE<-as.Date(stuckey$DATE,"%d-%m-%Y")

I always get NA

str(stuckey)

'data.frame': 502 obs. of  2 variables:
 $ DATE    : Date, format: NA ...
 $ IUMABEDR: num  11.33 10.69 10.26 9.91 9.98 ...

How could I solve this problem?

    
asked by Pintarraga 18.11.2016 в 14:19
source

1 answer

2

Hoa Pintarraga,

First of all, I recommend reading the documentation associated with the function as.Date ( ?base::as.Date ), the first argument is the string you want to transform to date and the second is the format.

In your case, you used the format "%d-%m-%Y" , with this you assume that the date string comes in 01-02-2014 format, for example, which is incorrect. For the above I suggest you read link with which you can know how to pause the date according to the pattern of the string.

To finish, the format that comes with your date is "%d %b %Y" where:

  • %d means day long 2 (1, 2, ... 31)
  • %b means abbreviated month: Jan Feb ... Dec
  • %Y means year of length 4, ex 2012.

I hope I help you;).

    
answered by 18.11.2016 в 19:45