Converting a localized date of the form 12-okt-2007

I have imported a time series with dates of the following format:

test = c("11-Feb-01","12-Feb-01","01-Mai-08")

This yields:

> as.Date(test, "%d-%b-%y") [1] NA NA "2008-05-01"

Since, May was translated it obviously takes locale into account.

According to the docs, the %b should be the abbreviated month name, but I guess there's might be some issue there.

How would I go about fixing this?

I'm running R under Linux t2.6.27-9-generic #1 SMP

Update: Digging a bit deeper i find that the issue is in the LC_TIME definition, where the appropriate abbrivations are of the form:

"jan.","feb.","mars", "apr", "mai", "juni", "juli", "aug.","sep.","okt.","nov.", "des."

while my data contains:

"Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Des"

I guess I could consider pre-processing the data, but a smooth way of doing this in R would be most welcome.

This works sort-of, but not so elegant:

> as.Date(gsub("Feb","feb.",test), "%d-%b-%y") [1] "2001-02-11" "2008-02-12" "2008-05-01"


-------------Problems Reply------------

The closest thing I've found to a solution is to make multiple iterations over the data to replace the names of the months with something that can be parsed.

I'm not sure if this is the best solution.


v <- read.csv2("valuta_dag.sdv",
na.strings = c("NA","ND"),
header = TRUE, sep=";", skip=2)

v$Dato <- gsub("Jan","01",v$Dato)
v$Dato <- gsub("Feb","02",v$Dato)
v$Dato <- gsub("Mar","03",v$Dato)
v$Dato <- gsub("Apr","04",v$Dato)
v$Dato <- gsub("Mai","05",v$Dato)
v$Dato <- gsub("Jun","06",v$Dato)
v$Dato <- gsub("Jul","07",v$Dato)
v$Dato <- gsub("Aug","08",v$Dato)
v$Dato <- gsub("Sep","09",v$Dato)
v$Dato <- gsub("Okt","10",v$Dato)
v$Dato <- gsub("Nov","11",v$Dato)
v$Dato <- gsub("Des","12",v$Dato)

v$Dato <- as.Date(v$Dato,"%d-%m-%y")

Category:r Views:0 Time:2009-01-24
Tags: r

Related post

  • How to convert Localized Date to standard Date in JavaScript? 2011-08-24

    I am writing a piece of javascript code to sort a table of data which contains a date (contains localized dates) and other fields. For eg: "lunes, 29 de agosto de 2011", "field1", "field2" "lunes, 28 de agosto de 2011", "field1", "field2"... while so

  • Timezone conversion - calculate GMT from local date and time 2013-07-01

    Re: I need to convert the local date and time I enter into one cell (PST -8:00) to GMT, and would like to verify

  • How to get regional timezone on Compact Framework and then convert UTC date to local date? 2010-02-15

    How to get regional timezone on Compact Framework and then convert UTC date to local date? --------------Solutions------------- The DateTime.ToLocalTime() method is available on CF, no need to jump through hoops. Do make sure to use a DateTime constr

  • Need a solution to convert and store date/time in correct local time compared to device timezone 2010-09-05

    Ok, I am not sure how to ask this question so that it can be understood... I need to store some schedules on a server (Ruby on Rails) from a iPhone. On the iPhone device the time is relative to the device timezone settings, but on the server I need t

  • How to convert time to date in the local timezone during query 2011-12-28

    We have a very simple payments model with the default "created_at" datetime field that we have to search in a date range so I did this: >> Payment.all(:conditions => ["Date(payments.created_at) >= ? and Date(payments.created_at) <= ?",

  • Converting Between Local Times and GMT/UTC in C/C++ 2009-04-17

    What's the best way to convert datetimes between local time and UTC in C/C++? By "datetime", I mean some time representation that contains date and time-of-day. I'll be happy with time_t, struct tm, or any other representation that makes it possible.

  • Converting from globalized date/time format (maybe ISO8601) to SQL Server datetime type 2009-06-26

    Is there a string format to represent a datetime that SQL will be able to parse and convert into another offset (EST -> UTC for example). I have a string from the user such as: declare @p1 varchar(50); declare @utcDateTime datetime; set @p1 = "200

  • Local data sources for GIS Map plugin? 2009-07-21

    I am developing an ASP.NET intranet application that needs to have an interactive map interface. There are some pretty neat Silverlight mapping plugins that I think could work well, specifically: ArcGIS Silverlight API:

  • Convert a summer date to utc in the winter? 2009-11-19

    The function mktime takes a struct tm as argument. One of the members of struct tm is tm_isdst. You can set this to 1 for wintertime, 0 for summertime, or -1 if you don't know. However, if during winter, you try to convert 2009-09-01 00:00, mktime fa

  • How to convert between local and universal time using boost::date_time? 2010-02-19

    How can I convert between local and UTC time (in particular, from local to UTC) using boost::date_time using a current system timezone? I know about boost::date_time::local_adjustor, but it requires a template argument which is a timezone-dependent o

  • Unicode Locale Data Markup for (e.g.) "Tue, 23 Feb 2010 06:00:44 PST" 2010-02-23

    I was parsing a XML feed and trying to convert it to a NSObject when I noticed that (e.g.) [NSDate dateFromString:@"Tue, 23 Feb 2010 06:00:44 PST"] returned nil. Then I tried to convert my string to a NSDate by using the NSDateFormatter. NSDateFormat

  • Does anyone know how to get the local date and time from Android 2.1 device? 2010-03-10

    Does anyone know know how to programatically get the local date and time of the Android device? With that local date and time, does anyone know how to convert that to milliseconds from 1970 in UTC time? --------------Solutions------------- These are

  • Converting a XSD date xs:dateTime to an Oracle Date 2010-08-23

    I need to convert a date from this format: 2002-10-10T12:00:00-05:00 (xs:dateTime as defined in XML) to an Oracle date. I'm used to using this in PL/SQL: to_date('date here', 'yyyymmdd'), is there a way to convert this while keeping the time zone inf

  • Using NSDateFormatter to format date to local date 2010-09-11

    I have tried numerous attemps of formatting a relatively simple date format to a date object, but also converting to my local time zone. All dates are formatte like this: 2010-09-11T08:55:00. This is GMT time, and I want it converted to a date object

  • Convert time and date from one time zone to another in PHP 2010-10-11

    Basically what I need is an script that, when provided with a time and a timezone can return the time in another time zone. My main issues are: Where to get the time offset from GMT from - is there a public database available for this? How to also ta

  • Do you need to convert a JavaScript Date to UTC before calling getVarDate? 2011-03-08

    I'm working with ActiveX controls in Internet Explorer and need to pass dates to the ActiveX methods that take dates as parameters. The methods expect dates to be of type, VT_DATE and I can produce VT_DATE values by using the JScript getVarDate metho

  • problem to convert string to date format on android 2011-08-28

    I just want to convert string to date format on android. my date is: Wed, 24 Aug 2011 08:28:44 +0200 I wrote this code: pubDate = "Wed, 24 Aug 2011 08:28:44 +0200"; //create SimpleDateFormat object with source string date format // "EEE, d MMM yyyy H

  • Xstream's jodatime Local Date display 2011-09-15

    I'm using xstrem to serialise a jodatime local date into xml. However when output the generated xml the LocalDate is not in an easily readable format. See below: <date> <iLocalMillis>1316563200000</iLocalMillis> <iChronology clas

  • Converting timezone-aware date string to UTC and back in Python 2011-09-19

    I'm parsing the National Weather Service alerts feed into a web application. I'd like to purge the alerts when they hit their expiration time. I'd also like to display the expiration time in the local time format for the geographic area they pertain

Copyright (C), All Rights Reserved.

processed in 0.172 (s). 11 q(s)