>> 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]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.