Hello Jim, I ran str() on the vector and it returned character:str("DF_exp.xlsx") chr "DF_exp.xlsx" I tried df2_TZ$DateTimeStamp <- strptime(as.Date(as.character(df2_TZ$DateTimeStamp, format = "%m/%d/%Y %H:%M", tz = "GMT"))), which produced an error: Error in charToDate(x) : character string is not in a standard unambiguous formatIn Excel, the column is formatted to m/d/yyyy h:mm Removing %S from these linesdf2_TZ$DateTimeStamp = as.POSIXct(df2_TZ$DateTimeStamp, format="%m/%d/%Y %H:%M", tz="GMT") df2_TZ$DateTimeStamp = as.POSIXct(as.character(df2_TZ$DateTimeStamp), format = "%m/%d/%Y %H:%M") made the column NA
Thank You,Doug Wolfinger On Friday, February 19, 2016 1:35 AM, Jim Lemon <drjimle...@gmail.com> wrote: Hi Doug,For one thing, you may be using the wrong format. Your example format has no seconds field. The other thing to watch is whether the data are in %m/%d/%Y or %d/%m/%Y date format. If the latter, you would probably get that error on dates like 19/02/2016. Jim On Fri, Feb 19, 2016 at 8:12 AM, D Wolf via R-help <r-help@r-project.org> wrote: Hello,I am trying to read a data frame column named DateTimeStamp. The time is in GMT in this format: 1/4/2013 23:30 require(xlsx) df2_TZ = read.xlsx2("DF_exp.xlsx", sheetName = "Sheet1") It's good to that line. But these three lines, which makes the dataframe, converts the column's values to NA:df2_TZ$DateTimeStamp = as.POSIXct(df2_TZ$DateTimeStamp, format="%m/%d/%Y %H:%M:%S", tz="GMT") and... df2_TZ$DateTimeStamp = as.POSIXct(as.character(df2_TZ$DateTimeStamp), format = "%m/%d/%Y %H:%M:%S") and...df2_TZ$DateTimeStamp = as.Date(df2_TZ$DateTimeStamp, format = "%m/%d/%Y %H:%M:%S") This line returns and error...df2_TZ$DateTimeStamp = as.POSIXct(as.Date(df2_TZ$DateTimeStamp), format = "%m/%d/%Y %H:%M:%S") "Error in charToDate(x) : character string is not in a standard unambiguous format" Additionally, I need to convert from GMT to North American time zones, and I think the advice on this page would be good for that: http://blog.revolutionanalytics.com/2009/06/converting-time-zones.html My ultimate goal is to write an R program that finds data in another variable in df2_TZ that corresponds to a date and time that match up with the date and time in another data frame. For now, any help reading the column would be much appreciated. Thank You,Doug [[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. [[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.