[R] Help

Greg Snow Greg.Snow at imail.org
Thu Jul 23 22:12:12 CEST 2009


Try:

> cbind( bm, res=apply(bm[,d],1 , sum) )

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Alberto Lora M
> Sent: Thursday, July 23, 2009 1:32 PM
> To: r-help at 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]]




More information about the R-help mailing list