[R] Add function to each row excluding certain columns

laro l_rohner at gmx.ch
Wed Oct 9 22:26:16 CEST 2013


Hello

I've got a matrix of the following form

	BARN	BCGE	BCVN	BEAN	Restriction 1	Restriction 2	Restriction 3	Restriction 4
Restriction 5
alpha.1	0.000172449	7.87E-05	-0.003271044	0.000921609	9.28E-19	2.00E-05
-0.000608211	NA	NA
alpha.2	0.000896744	0.000579453	-0.000623357	0.001260358	-1.36E-19	-5.22E-05
NA	NA	NA
alpha.3	0.000832748	0.00076229	0.002170229	0.001159895	3.09E-19	-7.86E-05	NA
NA	NA
alpha.4	0.000920545	NA	0.001680433	0.000459149	-3.08E-19	-3.59E-05	NA	NA	NA
alpha.5	0.001385238	0.000527484	0.000593311	0.000549358	7.72E-19	-6.99E-05
NA	NA	NA
alpha.6	0.000644262	0.000305714	-0.00044514	0.000407448	-9.68E-20	-5.56E-05
NA	NA	NA
alpha.7	-0.00022808	-0.00017047	0.000109545	0.000601197	0	3.50E-05	NA	NA	NA
alpha.8	-1.16E-05	-0.000105657	0.001403036	0.00058719	3.88E-19	8.64E-06	NA
NA	NA
alpha.9	0.000633559	-4.33E-05	0.000724611	0.000841646	-4.82E-20	-3.29E-05	NA
NA	NA

(see also file)


Now I'd like to calculate the maximal value of each row, but exclude
Restriction 1-5. An add a new column to the given matrix with the name 'MAX
without Restriction' and the mean of each row.

I tried 

max<-apply(example1,1,function(x)max(x))
new<-cbind(example,max)


but it gave a strange output, also I couldn't manage to exclude the columns
Restriction 1-5.

Thank you for your help!!

example1.txt <http://r.789695.n4.nabble.com/file/n4677914/example1.txt>  




--
View this message in context: http://r.789695.n4.nabble.com/Add-function-to-each-row-excluding-certain-columns-tp4677914.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list