I had a case yesterday where indexing with a real number was "close
enough".  I had about 4000 data point that I was plotting with just:

plot(x)

which would lay them out sequentially on the x-axis.  As a point of
reference, I want to put on the x-axis about 20 equally spaced tick marks
with the names of the vector items (each point had a name of it station).
To select the 20 points, I did

indx <- seq(1, length(x), length=20)
axis(1, at=indx, labels=names(x)[indx])

the values were "close enough" for my work.

I did not care rather it rounded up or down in this case; I just wanted a
name close to the value to plot on the x-axis

On Sun, Mar 14, 2010 at 9:09 AM, Bryan Hanson <hanson@depauw.edu> wrote:

> Jim, I completely agree with everything you said.
>
> I am curious about the cases where one would use a real number as an index
> and anticipate that R would do the as.integer for you, rather than turning
> it into an integer yourself.
>
> If anyone has a simple example or situation where this arises, I'd like to
> see it.  Of course, most cases might be rather idiosyncratic, and too
> complex to really share.  Just wondering mostly, because I am not a
> programmer by trade, and when I write code that uses indexing, and the
> proposed index comes up as a real number, I've generally made a mistake in
> my thinking!
>
> Bryan
>
>
> On 3/13/10 11:39 PM, "jim holtman" <jholtman@gmail.com> wrote:
>
> > That notation  'v[-1.18]' is not going to remove the 12th entry if it was
> > 1.18.  They should have used:
> >
> > v[-which(v == 1.18)]
> >
> > to remove it, but it probably would not have worked and we would have
> refered
> > them to FAQ 7.31.
> >
> > R is doing exactly what you are asking it to do.  There are cases where I
> have
> > used a real number and would not have expected an error.
> >
> > As you say, kids do the darnest things.  I use the comment that "users
> always
> > find new and unusual ways to use a system that the developers never
> > envisioned".  All we can do it tell them how it does work (for better or
> for
> > worse) and even if they think it is wrong, we can not change it as this
> point
> > in time to adapt to their way that they think it should work.
> >
> > R is a great learning experience for people and it allows you to
> experiment
> > without breaking things.  I still have to write little test cases every
> so
> > often to understand how things work, especially if you have NAs in your
> data
> > and you are trying to do some equality test or do a calculation on it.
> >
> > On Sat, Mar 13, 2010 at 9:39 PM, Bryan Hanson <hanson@depauw.edu> wrote:
> >> Hi all...
> >>
> >> My students were conflating grepping for a value in a vector to get the
> >> index, and then removing it with [-index], for instance like this:
> >>
> >> set.seed(17)
> >> v <- rnorm(20)
> >> s <- v[-1.18]
> >>
> >> They were trying to remove the 12th value in v, which is -1.18 or so.
> >>
> >> But the result is, as documented in ?Extract, to coerce 1.18 to the next
> >> lowest integer, and remove the 1st value of v, not the 12th value.
> >>
> >> This strikes me as something that ought to give an error or warning, or
> at
> >> least be in the R Inferno, but I couldn't find it there.
> >>
> >> Under what circumstances would the documented behavior be valuable?  I
> can
> >> see that it avoids doing floor or as.integer in computations where an
> index
> >> is needed but real numbers are generated for whatever reason, but is
> that
> >> common?
> >>
> >> Thanks for any insight.  Bryan
> >> *************
> >> Bryan Hanson
> >> Acting Chair
> >> Professor of Chemistry & Biochemistry
> >> DePauw University, Greencastle IN USA
> >>
> >> ______________________________________________
> >> R-help@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<http://www.r-project.org/posting-guide.html>
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
>
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]

