Re: [R] vector is not assigned correctly in for loop

2012-10-07 Thread 周果
Thank you all for helping me out. As Michael points out, I abused the rounding and formatting of print() while debugging. The default number of digits to print is 7 according to ?print.default, which makes floating point numbers to be somewhat plausible for index vector subsetting at first glance:

Re: [R] vector is not assigned correctly in for loop

2012-10-06 Thread R. Michael Weylandt
On Sat, Oct 6, 2012 at 3:23 PM, Bert Gunter wrote: > But the OP should not be doing this **at all.** He apparently has not > bothered to read the Intro to R tutorial as he appears not to know > about vectorized calculations. > > -- Bert > I don't really think that's relevant or constructive here.

Re: [R] vector is not assigned correctly in for loop

2012-10-06 Thread Bert Gunter
But the OP should not be doing this **at all.** He apparently has not bothered to read the Intro to R tutorial as he appears not to know about vectorized calculations. -- Bert On Sat, Oct 6, 2012 at 3:29 AM, R. Michael Weylandt wrote: > Forgot to cc the list. > > RMW > > On Sat, Oct 6, 2012 at 1

Re: [R] vector is not assigned correctly in for loop

2012-10-06 Thread Rui Barradas
Hello, This seems to be a case for FAQ 7.31 Why doesn't R think these numbers are equal? See this example: 3/5 - 1/5 - 2/5 # not zero 3/5 - (1/5 + 2/5) # not zero, different from above In your case, try for(idx in breaks){ print(idx / interval, digits = 16) # see problem indices

Re: [R] vector is not assigned correctly in for loop

2012-10-06 Thread R. Michael Weylandt
Forgot to cc the list. RMW On Sat, Oct 6, 2012 at 11:29 AM, R. Michael Weylandt wrote: > A case study of a good question! Would that all posters did such a good job. > > > > On Sat, Oct 6, 2012 at 7:14 AM, 周果 wrote: >> Hi there, >> Here is a minimum working example: >> -

Re: [R] vector is not assigned correctly in for loop

2012-10-06 Thread Berend Hasselman
On 06-10-2012, at 08:14, 周果 wrote: > Hi there, > Here is a minimum working example: > > lower = 0 > upper = 1 > n_bins = 50 > interval = (upper - lower) / n_bins > bins = vector(mode="numeric", length=n_bins) > breaks = seq(from=lo