Running a permutation test with different sample sizes in R Apply the permutation test with statistic $t = \bar{x} − \bar{y}$ to Example A, where $x$ and $y$ respectively refer to measurements with and without honey.
The data is

I just don't know how to account for the different sample sizes. Do I throw out some of the values or do I have to approximate the missing values with the mean? Originally learned it for equal sample sizes. With the equal sample sizes we subtracted column 1 from column 2. The original code for the equal sample size is
d <- A-B#subrract columns A from B
n <- length(d)#length of column
d.perm <- matrix(abs(d),n,1000)#create a matrix with a 1000 copies of d
d.perm <- d.perm*sign(runif(1000*n)-.5)#randomly generate + or - signs
d.bar <- apply(d.perm,2,mean)#get the mean of each column
mean($d.bar<mean(d)$)))#get a p-value of those $d.bar<mean(d)$

Need to account for the different sample sizes in the code. Thanks
Here is my updated code.
honey=c(19,12,9,17,24,24) 
no_honey=c(14,8,4,4,11,11)
t_stat=mean(honey)-mean(no_honey) 
combine=c(honey,no_honey) 
difference=rep(0,924) 
for (i in c(1:924)) { 
y=sample(combine) 
t_stat1=mean(y[1:6])-mean(y[7:12])
difference[i]=t_stat1 } 
p_value=sum(abs(difference)>abs(t_stat))/924 

 A: You need some assumptions if you are going to do a permutation test (otherwise nothing will be exchangeable under the null hypothesis).  If fact, you didn't even state that these were two independent simple random samples from two populations - as far as I know these could be two time series.
ASSUME (maybe):  Honey values are independent and identically distributed.  No honey values are independent and identically distributed.  The two samples are also independent of each other.
Let the Honey values have distribution F(t) and the No Honey values have distribution F(t-$\theta$).  Then $H_o: \theta = 0$ vs $H_a:  \theta \not= 0$.  Note that $\theta$ is the difference of the two population means (assuming they HAVE means...which is reasonable).
Then, under $H_o$, you can mix the two groups together, then split them randomly into samples of size 9 and 6, compute the difference of the means, then repeat.  This will give you the null distribution of the difference of the means.  You might consider:
temp = sample(c(Honey,NoHoney),replace=FALSE)
resample_honey = temp[1:9]
resample_nohoney = temp[10:15]
null[i] = mean(resample_honey) - mean(resample_nohoney)
A: The question tells you to use $\bar{x}-\bar{y}$ as a test statistic, not $\overline{x_i-y_i}$ (which is for paired observations). Indeed your code is for a paired problem, so you'll need to write new code.
Notionally, if the null hypothesis were true all 9+6 observations would be from the same population, and the group labels would be arbitrary. This suggests what you need to resample.
