[R] logical test not functioning correctly on zoo series...what the hell?
William Dunlap
wdunlap at tibco.com
Wed Mar 14 20:08:25 CET 2012
If you showed the output of dput(yourData) or even str(yourData)
others could see what types the columns are. Ordinary printed output can
make numeric, character, and factor data look the same. Comparisons
involving strings do not always return the same value as comparisons
involving the equivalent numbers. E.g.,
> y <- c("0.00", "0.01", "10.1", "20.2", "0.00")
> z <- zoo(y, as.POSIXct("2012-03-14")+(1:5)*24*60*60)
> z # looks like numeric data, but it is not
2012-03-15 2012-03-16 2012-03-17 2012-03-18 2012-03-19
0.00 0.01 10.1 20.2 0.00
> str(z)
'zoo' series from 2012-03-15 to 2012-03-19
Data: chr [1:5] "0.00" "0.01" "10.1" "20.2" "0.00"
Index: POSIXct[1:5], format: "2012-03-15" "2012-03-16" "2012-03-17" "2012-03-18" "2012-03-19"
> z[z>0]
2012-03-15 2012-03-16 2012-03-17 2012-03-18 2012-03-19
0.00 0.01 10.1 20.2 0.00
> z[z>"0.00"]
2012-03-16 2012-03-17 2012-03-18
0.01 10.1 20.2
> "0.0" > 0
[1] TRUE
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of R. Michael Weylandt
> Sent: Wednesday, March 14, 2012 11:39 AM
> To: knavero
> Cc: r-help at r-project.org
> Subject: Re: [R] logical test not functioning correctly on zoo series...what the hell?
>
> I'm getting a 404 on the dropbox link....looking at your pastebin
> link, my guess is that those numbers are in fact greater than zero,
> but are very small so they appear as zeros in the print method.
>
> If you want to send your data, it's easier to simply give us
> dput(rawData) and copy and paste the result into the email thread.
>
> I sincerely doubt that the world's most powerful and commonly used
> statistical software, after 20 years of development, can't test for
> something being greater than a literal.
>
> Michael
>
> On Wed, Mar 14, 2012 at 12:23 PM, knavero <knavero at gmail.com> wrote:
> > Here's the exact error I'm receiving:
> >
> > http://pastebin.com/mNsPauwk
> >
> > Tracked each output along the way. Starting to think there's a bug in the
> > source code.
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/logical-test-not-
> functioning-correctly-on-zoo-series-what-the-hell-tp4471654p4472337.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > 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.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list