McClatchie, Sam (PIRSA-SARDI)
2005-Aug-15 07:27 UTC
[R] return unique values from date/time class object
Background: OS: Linux Mandrake 10.1 release: R 2.0.0 editor: GNU Emacs 21.3.2 front-end: ESS 5.2.3 --------------------------------- Colleagues I have a wind speed time series with a normal frequency distribution and a spike in the 5 metres/second bin. The most likely explanation is that the instrument was returning duplicate values at this speed. To check this, I want to extract all the unique times from the series. However, unique() works with vectors and the object is POSIXt class. I've looked for a similar function to unique() that will work with this class, but have failed to find one. Any suggestions? Thanks Sam ---- Sam McClatchie, Biological oceanography South Australian Aquatic Sciences Centre PO Box 120, Henley Beach 5022 Adelaide, South Australia email <mcclatchie.sam at saugov.sa.gov.au> Cellular: 0431 304 497 Telephone: (61-8) 8207 5448 FAX: (61-8) 8207 5481 Research home page <http://www.members.iinet.net.au/~s.mcclatchie/> /\ ...>><xX(??> //// \\\\ <??)Xx><< ///// \\\\\\ ><(((??> >><(((??> ...>><xX(??>O<??)Xx><<
Hi Sam It works for me: ss<-Sys.time() sss<-rep(ss,5) ss<-Sys.time() sss<-c(sss,ss)> sss[1] "2005-08-15 10:04:02 St??edn?? Evropa (letn?? ??as)" "2005-08-15 10:04:02 St??edn?? Evropa (letn?? ??as)" [3] "2005-08-15 10:04:02 St??edn?? Evropa (letn?? ??as)" "2005-08-15 10:04:02 St??edn?? Evropa (letn?? ??as)" [5] "2005-08-15 10:04:02 St??edn?? Evropa (letn?? ??as)" "2005-08-15 10:04:35 St??edn?? Evropa (letn?? ??as)" # six values but only 2 different> unique(sss)[1] "2005-08-15 10:04:02 St??edn?? Evropa (letn?? ??as)" "2005-08-15 10:04:35 St??edn?? Evropa (letn?? ??as)" # 2 values> str(sss)'POSIXct', format: chr [1:6] "2005-08-15 10:04:02" "2005-08-15 10:04:02" "2005-08-15 10:04:02" "2005-08-15 10:04:02" "2005- 08-15 10:04:02" ... # posix format as well HTH Petr On 15 Aug 2005 at 16:57, McClatchie, Sam (PIRSA-SARDI) wrote:> Background: > OS: Linux Mandrake 10.1 > release: R 2.0.0 > editor: GNU Emacs 21.3.2 > front-end: ESS 5.2.3 > --------------------------------- > Colleagues > > I have a wind speed time series with a normal frequency distribution > and a spike in the 5 metres/second bin. The most likely explanation is > that the instrument was returning duplicate values at this speed. To > check this, I want to extract all the unique times from the series. > However, unique() works with vectors and the object is POSIXt class. > I've looked for a similar function to unique() that will work with > this class, but have failed to find one. > > Any suggestions? > > Thanks > > Sam > ---- > Sam McClatchie, > Biological oceanography > South Australian Aquatic Sciences Centre > PO Box 120, Henley Beach 5022 > Adelaide, South Australia > email <mcclatchie.sam at saugov.sa.gov.au> > Cellular: 0431 304 497 > Telephone: (61-8) 8207 5448 > FAX: (61-8) 8207 5481 > Research home page <http://www.members.iinet.net.au/~s.mcclatchie/> > > /\ > ...>><xX(??> > //// \\\\ > <??)Xx><< > ///// \\\\\\ > ><(((??> > >><(((??> ...>><xX(??>O<??)Xx><< > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
Prof Brian Ripley
2005-Aug-15 08:39 UTC
[R] return unique values from date/time class object
On Mon, 15 Aug 2005, McClatchie, Sam (PIRSA-SARDI) wrote:> Background: > OS: Linux Mandrake 10.1 > release: R 2.0.0Time for an update.> editor: GNU Emacs 21.3.2 > front-end: ESS 5.2.3 > --------------------------------- > Colleagues > > I have a wind speed time series with a normal frequency distribution and a > spike in the 5 metres/second bin. The most likely explanation is that the > instrument was returning duplicate values at this speed. To check this, I > want to extract all the unique times from the series. However, unique() > works with vectors and the object is POSIXt class. I've looked for a similar > function to unique() that will work with this class, but have failed to find > one.foo[!duplicated(unclass(foo))] works, for POSIXct (POSIXt is a virtual class covering that and POSIXlt: for the latter convert to POSIXct). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
McClatchie, Sam (PIRSA-SARDI)
2005-Aug-16 01:37 UTC
[R] return unique values from date/time class object
Background: OS: Linux Mandrake 10.1 release: R 2.1.1 editor: GNU Emacs 21.3.2 front-end: ESS 5.2.3 --------------------------------- Thanks to Brian Ripley (I've upgraded from source, thanks for the reminder) and Petr Pikal for their suggestions, but I have not made clear the form of my data: Browse[1]> ceduna[1:10,] LSD AVIATION_ID WND_DIR WND_SPD_MPS 1 1/01/2001 10:30:00 YCDU 230 4.6 2 1/01/2001 11:00:00 YCDU 210 4.1 3 1/01/2001 11:30:00 YCDU 230 6.7 4 1/01/2001 12:00:00 YCDU 230 7.7 5 1/01/2001 12:30:00 YCDU 220 8.2 6 1/01/2001 13:00:00 YCDU 210 7.2 7 1/01/2001 13:30:00 YCDU 210 7.2 8 1/01/2001 14:00:00 YCDU 200 6.7 9 1/01/2001 14:30:00 YCDU 190 7.7 10 1/01/2001 15:00:00 YCDU 200 8.2 Browse[1]> class(ceduna) [1] "data.frame" Browse[1]> x <- as.character(ceduna$LSD) Browse[1]> new.time <- strptime(x, "%d/%m/%Y %H:%M:%S") Browse[1]> class(new.time) [1] "POSIXt" "POSIXlt" Browse[1]> unique(new.time) Error in unique.default(new.time) : unique() applies only to vectors Browse[1]> tt <- new.time[!duplicated(unclass(new.time))] Error in duplicated.default(unclass(new.time)) : duplicated() applies only to vectors Browse[1]> I'm obviously doing something silly with the data classes, but what? Best fishes Sam ---- Sam McClatchie, Biological oceanography South Australian Aquatic Sciences Centre PO Box 120, Henley Beach 5022 Adelaide, South Australia email <mcclatchie.sam at saugov.sa.gov.au> Cellular: 0431 304 497 Telephone: (61-8) 8207 5448 FAX: (61-8) 8207 5481 Research home page <http://www.members.iinet.net.au/~s.mcclatchie/> /\ ...>><xX(??> //// \\\\ <??)Xx><< ///// \\\\\\ ><(((??> >><(((??> ...>><xX(??>O<??)Xx><<