[R] Date handling in R is hard to understand

Jim Lemon jim at bitwrit.com.au
Sat Nov 9 00:05:59 CET 2013

Hi Mihretu,
Can you grep for "AM" or "PM"? If so build your format string depending 
upon whether one of these exists in the date string.


On 11/09/2013 06:41 AM, Alemu Tadesse wrote:
> Dear All,
> I usually work with time series data. The data may come in AM/PM date
> format or on 24 hour time basis. R can not recognize the two differences
> automatically - at least for me. I have to specifically tell R in which
> time format the data is. It seems that Pandas knows how to handle date
> without being told the format. The problem arises when I try to shift time
> by a certain time. Say adding 3600 to shift it forward, that case I have to
> use something like:
> Measured_data$Date<- as.POSIXct(as.character(Measured_data$Date),
> tz="",format = "%m/%d/%Y %I:%M %p")+3600
> or Measured_data$Date<- as.POSIXct(as.character(Measured_data$Date),
> tz="",format = "%m/%d/%Y %H:%M")+3600  depending on the format. The date
> also attaches MDT or MST and so on. When merging two data frames  with
> dates of different format that may create a problem (I think). When I get
> data from excel it could be in any/random format and I needed to customize
> the date to use in R in one of the above formats. Any TIPS - for automatic
> processing with no need to specifically tell the data format ?
> Another problem I saw was that when using r bind to bind data frames, if
> one column of one of the data frames is a character data (say for example
> none - coming from mysql) format R doesn't know how to concatenate numeric
> column from the other data frame to it. I needed to change the numeric to
> character and later after binding takes place I had to re-convert it to
> numeric. But, this causes problem in an automated environment. Any
> suggestion ?
> Thanks
> Mihretu

More information about the R-help mailing list