Resampling without replacement in R, with a loop Here is the head of my data set (tjornres): 
       Fish.1 Fish.2  MORPHO      DIET 
1         1      2        0.03768       0.1559250 
2         1      3        0.05609       0.7897060 
3         1      4        0.03934       0.4638010 
4         1      5        0.03363       0.1200480 
5         1      6        0.05629       0.4390760 
6         1      8        0.08366       0.1866750 
7         1      9        0.04892       0.0988235 
8         1     10       0.04427       0.2637140 

MORPHO and DIET refer to the morphological and diet distances between fish 1 and fish 2. My original data set has over 2400 pairs of fish. My goal  is to resample this dataset by selecting only 435. 
I would like to do this 999 times and get a distribution of the correlation coefficients MORPHO~DIET. 
I went on and wrote this code: 
head(tjornres) 

essayres = tjornres                  # copy of the data             
R = 999                                         # the number of replicates             
cor.values = numeric(R)         # store the data             
for (i in 1:R) {                              # loop 
+ group1 = sample(essayres, size=435, replace=F) 
+ group2 = sample(essayres, size=435, replace=F) 
+ cor.values[i] = cor.test(group1,group2)$cor 
+ } 

I have a syntax error in this code. 
Also if I run one resampling, sample(essayres, size=435, replace=F), I get this error 
message: Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace,  
:cannot take a sample larger than the population when 'replace = FALSE'.

Does anyone know why this code is not working? Are there any other ways to resample (without replacement) ? 
Thank you for your help, 
 A: You should sample the observation number then subset the data based on those observation numbers.  So something like this:
group1 = essayres[sample(1:nrow(essayres), size=435, replace=F), ]

A: If you look under "sample" in the R documentation, you will see that "x [the first argument to sample] can be any R object for which length and subsetting by integers make sense".  For a data frame, length returns the number of columns:
> foo <- as.data.frame(matrix(0,100,8))
> str(foo)
'data.frame':   100 obs. of  8 variables:
 $ V1: num  0 0 0 0 0 0 0 0 0 0 ...
    ... blah blah blah ...
 $ V8: num  0 0 0 0 0 0 0 0 0 0 ...
> length(foo)
[1] 8

The number of columns in your data frame is, of course, less than 435, hence the error message.
What you can do is sample from the vector 1:nrow(essayres) and use the resulting sample to specify the rows of essayres in the relevant group, as in the answer that appeared while I was entering this one.
However, you have another problem: cor.test only accepts vectors.  You need to specify which columns of group1 and group2 you wish to test the correlation of.  Given your question statement, I strongly suspect you don't really want two groups at all, but rather something like:
N <- nrow(essayres)    
for (i in 1:R) {                             
      foo <- essayres[sample(1:N, size=435, replace=F),] 
      cor.values[i] = cor.test(foo$MORPHO, foo$DIET)$cor 
} 

