Hello everybody!
Im trying to define the optimal number of surveys to detect the highest number of species within a monitoring season/session. To do this I want to run all the possible combinations between a set of samples and to calculate the total number of species for each combination of 2, 3, 4 n samples events, so that at the end I will be able to define which is the lowest number of samples that I need to obtain the best result. Ive already done this operation manually, just to see if it works, but the point is that some of my datasets have more than 30 samples and more than 35 species, so that the number of combinations will be HUGE! So here is the question: I need to find a way for R to make all possible combinations of samples automatically, and then to automatically return the total number of species in every combination. Ive tried to search for a loop script, or something like that. However, Im relatively new to R and I dont know what I need to do Can anyone help me? Here Ive written a simple example of the operations I need to do, just to make my problem clearer. My dataset (matrix) has sample events by rows (U1,U2,U3) and detected species by columns. U<-read.table("C:\\Documents \\tre_usc.txt",header=T,row.names=1,sep="\t",dec = ",") U # global matrix with 3 samples SPECIE Aadi Aagl Apap Aage Bdia Beup Crub Carc Cpam U1 0 0 0 0 7 0 5 0 1 U2 0 0 0 0 4 2 1 0 0 U3 0 0 0 0 0 0 0 0 14 First, Ive created from this matrix all the subsets based on single samples, U1 <- U [c(1), ] U2 <- U [c(2), ] U3 <- U [c(3), ] U1 SPECIE Aadi Aagl Apap Aage Bdia Beup Crub Carc Cpam U1 0 0 0 0 7 0 5 0 1 U2 SPECIE Aadi Aagl Apap Aage Bdia Beup Crub Carc Cpam U2 0 0 0 0 4 2 1 0 0 Etc then Ive combined them summing each time the values of the chosen lines (total n° of combination = 4). U12<-U1+U2 U13<-U1+U3 U23<-U2+U3 U123<-U1+U2+U3 U12 SPECIE Aadi Aagl Apap Aage Bdia Beup Crub Carc Cpam U12 0 0 0 0 11 2 6 0 1 Etc . Then Ive applied the command length to find the number of species for every new combination. length(U12[U12>0]) [1] 4 length(U13[U13>0]) [1] 3 etc Now I need to do this with 10 and 32 sample events .: ( Thanks for your attention! Serena Corezzola Centro Nazionale per lo Studio e la Conservazione della Biodiversità Forestale, Bosco Fontana di Verona Strada Mantova 29 I-46045 MARMIROLO (MN) Italy [[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.