Try: > cbind( bm, res=apply(bm[,d],1 , sum) )
-- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Alberto Lora M > Sent: Thursday, July 23, 2009 1:32 PM > To: r-h...@stat.math.ethz.ch; R mailing list > Subject: [R] Help > > Dear R project group > > I have the following problem > > Let suppose the following data: > > > b<- > c("0","1","1","1","0","1","0","0","1","0","1","1","1","0","1","1","0"," > 1","1","0") > bm<-matrix(b,ncol=4) > colnames(bm)<-c("F1", "F2", "F3", "F4") > d<-c("F1","F4") > > For the matrix bm i need to create a fifth column. 1This column should > contain the sums of values where the columname is equal to the vector > d. > 2. I need to get the maximum and minimum value of this last column > The matrix result should be like this > > *F1* F2 F3 *F4 Res* > [1,] *"0"* "1" "1" "*1" "1" > *[2,] "1" "0" "1" "0" *"1"* > [3,] "1" "0" "1" "1" *"2"* > [4,] "1" "1" "0" "1" *"2"* > [5,] "0" "0" "1" "0" *"0"* > > Thxs again for your help > > > -- > Alberto Lora Michiels > Rue du Progrès, 6B > 7860 Lessines > GSM 32(0)496659457 > > [[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.