Hallo! <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p> I want to compare different samples with the formula <o:p></o:p> <o:p> </o:p> Here some example data: <o:p></o:p> <o:p> </o:p> <o:p> </o:p> sample1<o:p></o:p> sample2<o:p></o:p> sample3<o:p></o:p> sample4<o:p></o:p> a<o:p></o:p> 2.05<o:p></o:p> 2.65<o:p></o:p> 1.28<o:p></o:p> 1.85<o:p></o:p> b<o:p></o:p> 0<o:p></o:p> 6.69<o:p></o:p> 6.48<o:p></o:p> 4.86<o:p></o:p> c<o:p></o:p> 0<o:p></o:p> 44.13<o:p></o:p> 31.66<o:p></o:p> 30.21<o:p></o:p> d<o:p></o:p> 5.73<o:p></o:p> 18.96<o:p></o:p> 20.29<o:p></o:p> 13.65<o:p></o:p> e<o:p></o:p> 41.47<o:p></o:p> 52.73<o:p></o:p> 43.1<o:p></o:p> 52.88<o:p></o:p> f<o:p></o:p> 0<o:p></o:p> 2.78<o:p></o:p> 4.82<o:p></o:p> 1.56<o:p></o:p> g<o:p></o:p> 1.66<o:p></o:p> 2.72<o:p></o:p> 0<o:p></o:p> 2.47<o:p></o:p> h<o:p></o:p> 3.58<o:p></o:p> 10.98<o:p></o:p> 8.78<o:p></o:p> 9.11<o:p></o:p> i<o:p></o:p> 3.09<o:p></o:p> 3.6<o:p></o:p> 1.49<o:p></o:p> 3.72<o:p></o:p> j<o:p></o:p> 3.51<o:p></o:p> 5.38<o:p></o:p> 2.69<o:p></o:p> 4.1<o:p></o:p> k<o:p></o:p> 2.87<o:p></o:p> 4.14<o:p></o:p> 3<o:p></o:p> 2.87<o:p></o:p> l<o:p></o:p> 5.96<o:p></o:p> 7.26<o:p></o:p> 3.45<o:p></o:p> 4.8<o:p></o:p> m<o:p></o:p> 3.87<o:p></o:p> 11.56<o:p></o:p> 7.28<o:p></o:p> 3.15<o:p></o:p> <o:p> </o:p> The rows are amounts of substances found in plant samples. Some substances are not present in some samples (=0). <o:p></o:p> <o:p> </o:p> The formula: Xi = (sum (from i=1 to n) (pi/Pi))/ n <o:p></o:p> <o:p> </o:p> *Xi* is a measure for the similarity of chromatograms with an ideal value of 1 (100 % similarity)*,n *is the number of peaks in both chromatograms to compare. xi is a measure for the similarity of the peaks in chromatograms.* **pi* is the integration (area) of the peak i (i=1 to n) of one chromatogram and *Pi,* the integration of the peak i (i=1 to n) of the other chromatogram. <o:p></o:p> The amount of each substance in two samples, sum it up and divide it through the total number of substance. (In the table above maximum 14). <o:p></o:p> At the moment I have this: <o:p></o:p> <o:p> </o:p> ksi <- function(a,b) { <o:p></o:p> p <- apply(cbind(a,b),1,min) <o:p></o:p> P <- apply(cbind(a,b),1,max) <o:p></o:p> piPi <- p[P>0]/P[P>0] print(piPi) <o:p></o:p> ksi <- sum(piPi)/sum(as.numeric(P>0)) <o:p></o:p> } <o:p></o:p> <o:p> </o:p> d <- read.csv('data.csv') <o:p></o:p> n.prob <- 5 <o:p></o:p> x <- matrix(1,n.prob,n.prob) <o:p></o:p> for (i in 2:n.prob) for (j in 1:(i-1)) { <o:p></o:p> print(paste(i,j)) <o:p></o:p> x[i,j] <- ksi(d[,i+1], d[,j+1]) <o:p></o:p> x[j,i] <- x[i,j] <o:p></o:p> } <o:p></o:p> rownames(x)<-names(d)[-1] <o:p></o:p> colnames(x)<-names(d)[-1] <o:p></o:p> x<o:p></o:p> <o:p> </o:p> How can I change it that pi isnt the smaller number and P1 is the bigger one. <o:p></o:p> P1 should always the number of e. g. sample 1 and P1 of sample 2. Yours, Serena <o:p></o:p> Run, Fatboy, Run" sowie "Rails & Ties" kostenlos anschauen! Blockbuster-Gutscheine sichern unter *http://www.blockbuster.web.de* [http://www.blockbuster.web.de] [[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.