progamming functions help
Stephen Cole wrote:
Not sure if i should really post this here, but i am an ecology student and my project is certainly ecological so........ my goal is to use R to write functions for and automate a series of analyses i would like to do on a large data set. The calculations are not very difficult in themselves, however they will be very time consuming (Plus I think R will be extremely useful and this is another excuse to learn how to program). I have a vector of 20 values x <- c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26, 26,30) 1. I want to select random pairs from this data set but do it without replacement exhaustively I know i can select random pairs without replacement using sample(N,n,replace=F) However i am wondering if there is any way to get 10 random pairs from this data set without repeating any of the data points that is to say if i got a (20, 94) for one pair, i would like to get 9 other pairs from the data without again getting 20 or 94?
x <- c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26, 26,30) matrix(sample(x), ncol=2)
2. The second thing i would like to do is be able to select all possible pairs of numbers and calculate each pairs variance. I think i will need a for loop here but I am unsure of how to do the programing. I am reading two books on S and s-plus now and hope they are some help. I thought i would also post on this list and get some expert advice for the more experienced R users
## All possible pairs uu <- expand.grid(x,x) ## the variance on two values? are you sure? ## technically: apply(uu, 1, var) HTH Cl?ment
Thank-you very much Stephen Cole Marine Ecology Lab Saint Francis Xavier University
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Cl?ment CALENGE Office national de la chasse et de la faune sauvage Saint Benoist - 78610 Auffargis tel. (33) 01.30.46.54.14