Permutation test in R I have the following data for 10 subjects based on before and after measurements:
x <- c(12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3) 
y <- c(12.7, 13.6, 12.0, 15.2, 16.8, 20.0, 12.0, 15.9, 16.0, 11.1)

and would like to perform a permutation test.
I used the permTS(...) to perform a two-sided t-test and obtained a value of 0.982.
But I would like to use the expand.grid(rep(x,k )) by interchanging the before and after tags. Does anyone know how this can be achieved?
Given the numbers of possible permutations it is not possible to stimulate every permutation, hence why I would like to use expand.grid to check if the same result is obtained.
Thanks
 A: You should be using a paired T-test since these are paired data, not a 2 sample test.
All possible permutations of pre-post data would be obtained using
expand.grid(pre=x, post=y)
And we know it's only a 2 by 100 matrix which is far from impossible. I don't know why you're replicating x, or what k is.
A: What you are saying is you would like to compare the paired t-test statistic to the distribution of such statistics obtained by independently switching all possible pairs of data.  There are $2^{10}=1024$ such switches, small enough to enable fast computation of the full distribution.
It is convenient in R to code this as a t-test for the difference between the two sets of data: instead of switching values, we merely need to negate them. 
Let's first run the t-test:
x <- c(12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3)
y <- c(12.7, 13.6, 12.0, 15.2, 16.8, 20.0, 12.0, 15.9, 16.0, 11.1)
(value <- t.test(x,y, paired=TRUE, alternative="two.sided"))

The statistic and p-value are $-0.213$ and $0.836$, as expected.  Now let's generate the permutation distribution (using expand.grid as requested):
perms <- do.call(expand.grid, lapply(as.list(1:length(x)), function(i) c(-1,1)))
dist <- apply(perms, 1, function(p) t.test(p*(x-y), alt="t")$statistic)

(This takes $0.33$ seconds.)  As a quick check, let's graph the results:
hist(dist)
abline(v = value$statistic, col="Red", lwd=2)


Because the actual statistic is near the middle of the distribution and this is a two-sided test, the p-value looks approximately to be $0.9$ or so.  We can compute it:
sum(abs(dist) > abs(value$statistic)) / 2^length(x)

The result is $0.836$, the same as the t-distribution gave us.
