Thanks to the people on this list I was able to fix my code for randomly
sampling.  Thanks.  

 

Now, I am moving on to the next step and I ran into another snag.  I have a
large dataset but I am starting with a small made-up dataset until I figure
it out.  I have two columns of data (age and length).  I got R to read my
data called growth which is the age and length for 10 fish:  

 

> growth

  Age Length

1   2    200

2   5    450

3   6    600

4   7    702

5   8    798

6   5    453

7   4    399

8   1    120

9   2    202

 

Then I believe I converted my data to a three vectors by: 

 

newgrowth<-c(growth)

 

Now I want to randomly select the values from this dataset to create a new
dataset.  I want to do this many times, however, for now I am just trying to
get it to randomly select from the dataset only once.  The trick is that I
need to keep the columns together.  Each age corresponds to a length.  For
example, the 200 length fish has an age of 2 years.  

 

I tried to resample the data with this code:   

 

sample(newgrowth)

 

However, I ended up getting the data listed as a row in the same order, not
randomly selected.  I pasted the result below.  

 

> sample(newgrowth)

$Age

[1] 2 5 6 7 8 5 4 1 2

 

$Length

[1] 200 450 600 702 798 453 399 120 202

 

Any advice on how I can randomly select from these 9 rows of data would be
greatly appreciated.  

 

Mike


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to