Thanks for the gracious assistance in advance I'm working on a non-metric scaling problem and am calculating the distance for input to isoMDS Here is the code library(MASS) vegdata <- tapply(Percent, list(PRIMARY_VE, MASTERID), sum) x.mat <- matrix(x, nrow=40, ncol=2750, byrow=TRUE, dimnames c(dimnames(x)[1], dimnames(x)[2])) vegdata.dd <- dist(x) vegdata.dd <- ifelse(vegdata.dd==NA, 0.01, x.dd) vegdata.dd Everything works as expected until I try to replace the NA values in the distance matrix. the ifelse statement converts the entire dataset to NA. What am I doing incorrectly? Once again, Thanks Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 Office (305) 224 - 4282 Steve_Friedman at nps.gov
Try the following instead: vegdata.dd[is.na(vegdata.dd)] <- 0.01 -Christos> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of > Steve_Friedman at nps.gov > Sent: Friday, October 17, 2008 4:50 PM > To: r-help at stat.math.ethz.ch > Subject: [R] using ifelse with surprising results > > > Thanks for the gracious assistance in advance > > I'm working on a non-metric scaling problem and am > calculating the distance for input to isoMDS > > Here is the code > > library(MASS) > vegdata <- tapply(Percent, list(PRIMARY_VE, MASTERID), sum) > x.mat <- matrix(x, nrow=40, ncol=2750, byrow=TRUE, dimnames = > c(dimnames(x)[1], dimnames(x)[2])) > > > vegdata.dd <- dist(x) > vegdata.dd <- ifelse(vegdata.dd==NA, 0.01, x.dd) > vegdata.dd > > Everything works as expected until I try to replace the NA > values in the distance matrix. > the ifelse statement converts the entire dataset to NA. > > What am I doing incorrectly? > > Once again, Thanks > > Steve > > > Steve Friedman Ph. D. > Spatial Statistical Analyst > Everglades and Dry Tortugas National Park 950 N Krome Ave > (3rd Floor) Homestead, Florida 33034 > > Office (305) 224 - 4282 > Steve_Friedman at nps.gov > > ______________________________________________ > R-help at 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. > >
On Fri, Oct 17, 2008 at 3:50 PM, <Steve_Friedman at nps.gov> wrote:> > Thanks for the gracious assistance in advance > > I'm working on a non-metric scaling problem and am calculating the distance > for input to isoMDS > > Here is the code > > library(MASS) > vegdata <- tapply(Percent, list(PRIMARY_VE, MASTERID), sum) > x.mat <- matrix(x, nrow=40, ncol=2750, byrow=TRUE, dimnames > c(dimnames(x)[1], dimnames(x)[2])) > > > vegdata.dd <- dist(x) > vegdata.dd <- ifelse(vegdata.dd==NA, 0.01, x.dd) > vegdata.dd > > Everything works as expected until I try to replace the NA values in the > distance matrix. > the ifelse statement converts the entire dataset to NA. > > What am I doing incorrectly?What does NA == NA equal? This is not intuitive (at first!) but very important when dealing with NAs. Hadley -- http://had.co.nz/