Hi, there. I have two matrix with identical dimentions. matrix A contains information of 0 and 1, and matrix B contains data. I only want the data in matrix B where matrix A has 1's. the places where matrix A has 0's, I want NA's in matrix B. How do I do that?? Thank you very much. Lei Jiang Department of Chemsitry University of Washington Box 351700 Seattle, WA 98195 Phone: 206-616-6882 Fax: 206-685-8665
If you just multiply the two together, you get 0 in the right positions. If you want those to be NAs, just do: result <- ifelse(A, B, NA) Andy> From: Lei Jiang > > Hi, there. > > I have two matrix with identical dimentions. matrix A contains > information of 0 and 1, and matrix B contains data. I only > want the data > in matrix B where matrix A has 1's. the places where matrix A > has 0's, I > want NA's in matrix B. > > How do I do that?? > > Thank you very much. > > Lei Jiang > > Department of Chemsitry > University of Washington > Box 351700 > Seattle, WA 98195 > Phone: 206-616-6882 > Fax: 206-685-8665 > > ______________________________________________ > R-help at 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 > > >
Jiang, This example could help: A <- matrix(rbinom(20,1,.8),ncol=2) B <- cbind(rnorm(20,-1,0),rnorm(20,1,0)) B <- ifelse(A==0,NA,B) B A S M Mwalili. Lei Jiang <lj22@u.washington.edu> wrote: Hi, there. I have two matrix with identical dimentions. matrix A contains information of 0 and 1, and matrix B contains data. I only want the data in matrix B where matrix A has 1's. the places where matrix A has 0's, I want NA's in matrix B. How do I do that?? Thank you very much. Lei Jiang Department of Chemsitry University of Washington Box 351700 Seattle, WA 98195 Phone: 206-616-6882 Fax: 206-685-8665 ______________________________________________ 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 --------------------------------- [[alternative HTML version deleted]]
I am having trouble figuring out this one. I want to do a one way anvoa with 13 levels. mydata is in a vector with length 65. each level has 5 repeats. but it contains NA. I made mygroup<-gl(13, 5, 65, labels=(...)) anova(lm(mydata ~ mygroup)) it gives following error: Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type Can you please help?? Millions of thanks. Lei Jiang Department of Chemsitry University of Washington Box 351700 Seattle, WA 98195 Phone: 206-616-6882 Fax: 206-685-8665