From: Gregory Snow <Greg.Snow_at_intermountainmail.org>

Date: Wed 14 Dec 2005 - 04:42:51 EST

Date: Wed 14 Dec 2005 - 04:42:51 EST

Does this do what you want:

IED <- function(risk){

tmp <- outer(risk,risk,"-") tmp <- abs(tmp) return(tmp[lower.tri(tmp)])

}

-- Gregory L. Snow Ph.D. Statistical Data Center, IHC greg.snow@intermountainmail.org (801) 408-8111Received on Wed Dec 14 06:31:43 2005

> -----Original Message-----

> From: r-help-bounces@stat.math.ethz.ch> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of> Oarabile Molaodi> Sent: Tuesday, December 13, 2005 5:00 AM> To: r-help@stat.math.ethz.ch> Subject: [R] help with writing function>> I'm trying to write a function that takes a vector of length> n and then takes the first value of the vector i.e j=1 and> forms a new vector of length n (i.e replicate the first value> n times). This function will then calculate the absoulte> difference of the original vector and the new vector and> store the results omitting the difference between the value> and itself. This function should be able to repeat the> procedure for each of the j's i.e j=2 to n. The results> should all be stored together. Below is what I've tried so> far but it seems to work only for> j=1 .>> Your help will be highly appreciated.> IED<-function(risk){> n<-length(risk)> i<-c(1:n)> Diff<-numeric()> for(j in 1:n){> relrisk<-risk> relrisk[i]<-relrisk[j]> Difference<-abs(risk-relrisk)> Difference<-Difference[-c(1:j)]> Difference<-append(Diff,Difference)> return(Difference)> }> }>>> Oarabile>> ______________________________________________> R-help@stat.math.ethz.ch mailing list> https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide!> http://www.R-project.org/posting-guide.html

> ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

*
This archive was generated by hypermail 2.1.8
: Wed 14 Dec 2005 - 09:34:04 EST
*