Comparing two means using permutation test and bootstrapping with the boot() function in R I would like to know how to do a permutation test using the boot function in R. The goal is to compare means of two groups of people: some of them drink beer and the other one drink water. 
The problem that I have is how to write the statistical function I will use in the boot(). 
In fact, I would like to know how to incorporate the sampling process in the statistical function that I have to write.
Please any help. Here is the data set that I have
Mpoudas
   Response Treatment
1        27      Beer
2        20      Beer
3        21      Beer
4        26      Beer
5        27      Beer
6        31      Beer
7        24      Beer
8        21      Beer
9        20      Beer
10       19      Beer
11       23      Beer
12       24      Beer
13       28      Beer
14       19      Beer
15       24      Beer
16       29      Beer
17       18      Beer
18       20      Beer
19       17      Beer
20       31      Beer
21       20      Beer
22       25      Beer
23       28      Beer
24       21      Beer
25       27      Beer
26       21     Water
27       22     Water
28       15     Water
29       12     Water
30       21     Water
31       16     Water
32       19     Water
33       15     Water
34       22     Water
35       24     Water
36       19     Water
37       23     Water
38       13     Water
39       22     Water
40       20     Water
41       24     Water
42       18     Water
43       20     Water

 A: While permutations tests, randomization tests and bootstrapping all fall under the class of resampling procedures, they differ in some important ways.
In particular, a permutation test differs in several respects from bootstrapping; you seem to think they're the same thing.
Some of these differences will make it essentially impossible to use bootstrapping to do a permutation test.


*

*a "full" permutation test doesn't actually sample at all. Every data point reappears in every possible sample re-arrangement of the group labels, and it uses every one of the sample combinations that the randomization test samples from; the complete permutation distribution of the test statistc is computed. In practice that's only possible with fairly small samples - or with use of clever algorithms, often to middling sort of sample sizes (dozens of observations, even more in some cases).

*You could sample the permutation distribution (which some authors call a randomization test, though other authors use that term to mean something a little different). This involves a form of sampling the data without replacement, in the sense that every observation appears (in possibly some modified form) in each resample. However, these (re)arrangements of the original sample themselves are sampled with replacement from the collection of possible arrangements of the group labels that the complete permutation test uses (as described below)

*bootstrapping involves sampling the data with replacement. Some observations in a typical bootstrap sample will occur more than once, others will not be present. On average about 62% recur in a given sample.
Bootstrapping has different assumptions and properties from this approach to randomization testing.


*

*Here's how you'd do a full permutation test of the situation you describe:
a. for every possible allocation of 25 "beer" labels and 18  "water" labels to the 43 observations of the response variable, compute the beer-mean minus the water mean.
b. find the proportion of such allocations (out of the $6.08\times 10^{11}$ combinations just calculated) that have the absolute value of the mean at least as far from 0 as your sample data. That's your exact p-value for the permutation test

*Here's how you'd do a resampled permutation test (/randomization test) of it:
a. for some large number of replications, choose allocations at random from the set of possible label-rearrangements discussed in 1 and compute the difference in means (sampling with replacement).
b. add your sample into the set. Find the proportion of sampled allocations that have the absolute value of the mean at least as far from 0 as your sample data. That's your simulated p-value for the randomization test. As you sample more, the uncertainty in the p-value goes down. You can estimate the standard error of the p-value estimate since it's a binomial proportion.

*Here's one way you could do a bootstrap test of that (glossing over some of the details in the interest of brevity):
a. Repeat many times: sample with replacement from the "beer" group to get a 'beer' pseudosample. Sample with replacement from the "water" group to get a 'water' pseudosample. 
b. use the distribution of the difference in pseudosample means to construct a confidence interval for the difference in means (several methods are discussed in chapter 5 of Davison & Hinkley). If that CI doesn't include 0, conclude that the difference in means is different from 0.

*Here's another simple way: 
a. resample both groups as in 3a and take the difference. Subtract the difference in the original sample means. (repeated many times; this produces a resampled distribution of differences that has the "shape" as that which results from treating the ecdf like a population distribution but where the mean population difference matches the case under the null)
b. Find where the sample difference in means occurs in this distribution (computing the relevant p value accordingly).
(Davison & Hinkley describe better but more complicated one sample bootstrap test than this - e.g. the studentized bootstrap in Section 4.4.1 of their book. They mention several other possible bootstrap tests for this situation, including one very like a resampled permutation test, but where sampling is with replacement.)
The easy way to do a resampled permutation test (/randomization) test in R isn't to use the boot function at all, but to use the sample function, since that draws without replacement.
Short of reading Davison and Hinkley, you might try these resources on bootstrapping and R:
Ajay Shah's introduction
Quick R on the bootstrap
John Fox's appendix chapter on the bootstrap 
Canty's discussion of the boot package
Davison and Kuonen on bootstrap applications in R
