Sampling with and without replacement I seem unable to use "replace = F" when I want to sample without replacement. I would think that it comes down to "F is not a legitimate abbreviation for FALSE." except that Dalgaard (p. 118) uses F for FALSE and it works "pairwise.t.test(folate, ventilation, pool.sd = F)" I am having trouble when I try to sample a vector without replacement. The following code illustrates my problem. >b <- c(1:8) >sample(b) [1] 7 8 3 5 1 6 2 4 # That works correctly--no replacement (This would be my preferred form, but when I look at the code later it is helpful to know explicitly how I did the sampling.) > sample(b, replace = T) [1] 7 5 6 2 5 5 4 7 # That is also correct--replacement > sample(b, replace = F) [1] 1 7 3 7 3 4 6 5 # There are two 3s and two 7s, so there was replacement >sample(b, replace = FALSE) [1] 8 1 3 2 5 6 7 4 # That works just fine >sample(b, replace = "F") [1] 5 3 2 8 4 1 7 6 # quoting the F is fine. If it is OK to replace TRUE with T, why can't I replace FALSE with F? I have a similar problem if I write data <= read.table(file.choose(), header = F) I'm using a Windows machine with version 2.8.0, but I'm sure that this is not a machine specific problem. Thanks, Dave Howell -- David C. Howell PO Box 770059 627 Meadowbrook Circle Steamboat Springs, CO 80477
On 17/11/2008, at 1:56 PM, David C. Howell wrote:> Sampling with and without replacement > > I seem unable to use "replace = F" when I want to sample without > replacement. I would think > that it comes down to "F is not a legitimate abbreviation for FALSE." > except that > Dalgaard (p. 118) uses F for FALSE and it works > "pairwise.t.test(folate, ventilation, pool.sd = F)" > > I am having trouble when I try to sample a vector without replacement. > > The following code illustrates my problem.<snip> (a) Naughty Peter. It works, but is ill-advised. The difference is that FALSE is a reserved word (as is TRUE) but F and T are *not* reserved. (b) Try find("F") --- I conjecture that you have an object named "F" (not equal to FALSE) floating around somewhere in your search path. Remove or rename this, and your ``replace=F'' will work. But .... ***DON'T DO THAT***!!! Use FALSE when you mean FALSE. Don't use F. It causes trouble. (Note: You *cannot* have spurious objects name "FALSE" (and not equal to FALSE) hanging around; R won't let you. That's why you use FALSE and not F.) cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
It is better programming practice to use FALSE for false and TRUE for true, and not F and T. This is because it is quite legal to do this: T <- FALSE F <- TRUE or any other assignment. If you re-assign T or F (which are set to TRUE and FALSE at the beginning of a session), you run into the sort of problem that you have discovered. Also, there is the F and t distributions, and the t() function, so having variables called F and T may lead to further confusion. If you mean FALSE, say FALSE. If you mean TRUE, say TRUE. Cheers, Simon. On Sun, 2008-11-16 at 17:56 -0700, David C. Howell wrote:> Sampling with and without replacement > > I seem unable to use "replace = F" when I want to sample without > replacement. I would think > that it comes down to "F is not a legitimate abbreviation for FALSE." > except that > Dalgaard (p. 118) uses F for FALSE and it works > "pairwise.t.test(folate, ventilation, pool.sd = F)" > > I am having trouble when I try to sample a vector without replacement. > > The following code illustrates my problem. > > >b <- c(1:8) > > >sample(b) > [1] 7 8 3 5 1 6 2 4 # That works correctly--no replacement > (This would be my preferred form, but when I look at the code later it > is helpful to know > explicitly how I did the sampling.) > > > sample(b, replace = T) > [1] 7 5 6 2 5 5 4 7 # That is also correct--replacement > > > sample(b, replace = F) > [1] 1 7 3 7 3 4 6 5 # There are two 3s and two 7s, so there was > replacement > > > >sample(b, replace = FALSE) > [1] 8 1 3 2 5 6 7 4 # That works just fine > > >sample(b, replace = "F") > [1] 5 3 2 8 4 1 7 6 # quoting the F is fine. > > > If it is OK to replace TRUE with T, why can't I replace FALSE with F? > > > I have a similar problem if I write data <= read.table(file.choose(), > header = F) > > I'm using a Windows machine with version 2.8.0, but I'm sure that this > is not a machine specific problem. > Thanks, > Dave Howell >-- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey.