[R] replace values in a distance matrix

From: Mari Carmen Garcia Esteban <mc_gar_est_at_yahoo.es>
Date: Fri 28 Jul 2006 - 02:25:51 EST


Hi to everybody!
  I´m just a beginner in R, and I´m trying to replace values in a distance matrix with a concret condition: replace all values (elements) lower than 4.5 with value=18.    

  I´ve tried this, but it doesn´t work...    

  Dxy would be my 117 x 117 euclidean distance matrix    

    M18 and M4.5 would be 117 x 117 matrices:    

  M18<-matrix(rep(18,13689),nrow=117)
  M4.5<-matrix(rep(4.5,13689),nrow=117)    

  REPLACE ALL VALUES >4.5 WITH 18.0 in Dxy    

  for(i in 1:117) {
  for(j in 1:117) {
  Dxy[i,j]<-ifelse(Dxy[i,j]<M4.5[i,j],Dxy[i,j],M18[i,j])
}
}
   

  Thanks in advance!    

  Mari Carmen Garcia
  Ud. Anatomía, Fisiologia y Génetica.
  Escuela Técnica Superior de Ingenieros de Montes de Madrid   Spain.                              


        [[alternative HTML version deleted]]



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 and provide commented, minimal, self-contained, reproducible code. Received on Fri Jul 28 02:30:33 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 28 Jul 2006 - 04:18:49 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.