[R] Time format issue
    Ismail SEZEN 
    sezenismail at gmail.com
       
    Wed Jul 27 14:03:58 CEST 2016
    
    
  
>> The time column is factor. I want to convert each time to the following
>> format:
>> 
>> 20111211003000
>> 
>> 20111211013000
>> 
>> 20111211020000
>> 
>> (Year)(month)(date)(hr)(min)(sec)
> 
>> newTimeDt <- strptime(Time, format="%d%b%y:%H:%M")
>> newTimeDt
> [1] "2011-12-27 00:30:00 PST" "2011-12-27 01:30:00 PST" "2011-12-27 02:00:00 PST"
>> newTimeDt <- as.POSIXct(Time, format="%d%b%y:%H:%M")
>> newTimeDt
> [1] "2011-12-27 00:30:00 PST" "2011-12-27 01:30:00 PST" "2011-12-27 02:00:00 PST"
>> newOut <- format(newTimeDt, "%Y%m%d%H%M")
>> newOut
> [1] "201112270030" "201112270130" "201112270200"
>> newOut <- format(newTimeDt, "%Y%m%d%H%M%S")
>> newOut
> [1] "20111227003000" "20111227013000" "20111227020000"
Addition to David, if you use functions similar to read.csv or read.table to read dates from a file, you have to set 
stringsAsFactors = T
in function parameters or set data.frame column as character seperately.
	[[alternative HTML version deleted]]
    
    
More information about the R-help
mailing list