HI, I have to work with data objects. I have trouble. I would like to convert date to a integer of Julian dates omitting hours, minutes etc. I tried as. Date and also as.POSIXlt, ct etc. Please help me to compute the following difference. I get an "NA" for output. 1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM Thanks. Chetty -- Professor of Family Medicine Boston University Tel: 617-414-6221, Fax:617-414-3345 emails: chettyvk@gmail.com,vchetty@bu.edu [[alternative HTML version deleted]]
On Apr 21, 2012, at 1:17 PM, Veerappa Chetty wrote:> HI, > I have to work with data objects. I have trouble. I would like to > convert > date to a integer of Julian dates omitting hours, minutes etc. I > tried as. > Date and also as.POSIXlt, ct etc. > > Please help me to compute the following difference. I get an "NA" for > output. > > 1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AMI didn't realize this until I started experimenting with your example, but there is no 0 hour that is recognized by strptime when using the am/pm time format: > strptime("1/14/2006 0:01:01 AM", format ="%m/%d/%Y %I:%M:%S %p") [1] NA > strptime("1/14/2006 12:01:01 AM", format ="%m/%d/%Y %I:%M:%S %p") [1] "2006-01-14 00:01:01" If you want to offer a reproducible example of your data (not just console output we can do more with it.) I suggest you take you vector and offer the output of dput() on it. -- David.> > > Thanks. > Chetty > -- > Professor of Family Medicine > Boston University > Tel: 617-414-6221, Fax:617-414-3345 > emails: chettyvk at gmail.com,vchetty at bu.edu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.David Winsemius, MD West Hartford, CT
Hello, Veerappa Chetty wrote> > HI, > I have to work with data objects. I have trouble. I would like to convert > date to a integer of Julian dates omitting hours, minutes etc. I tried as. > Date and also as.POSIXlt, ct etc. > > Please help me to compute the following difference. I get an "NA" for > output. > > 1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM > > > Thanks. > Chetty > -- > Professor of Family Medicine > Boston University > Tel: 617-414-6221, Fax:617-414-3345 > emails: chettyvk@,vchetty@ > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@ mailing list > 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. >Maybe this is system dependent, but with me, unlike what the help for 'strptime' says, the format character 'H' can be used with the am/pm indicator even if 'p' is present.> x <- c("1/14/2006 0:00:00 AM", "1/9/2006 0:00:00 AM") > # With '%p' in format string > d <- strptime(x, format ="%m/%d/%Y %H:%M:%S %p") > d[1] - d[2]Time difference of 5 days> # Without '%p' > d <- strptime(x, format ="%m/%d/%Y %H:%M:%S") > d[1] - d[2]Time difference of 5 days> > sessionInfo()R version 2.14.1 (2011-12-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.14.1 And the minus operator works as expected. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Date-object-tp4576784p4577018.html Sent from the R help mailing list archive at Nabble.com.