r - Add a variable to a data frame containing max value of each row -


I want to add a variable (column) to each variable in a data frame ( df ) < / P>

  df $ max [1] & lt; - Max (DF [1,2: 26])  

I'm looking for a way to generalize for 1 to 865 rows. If I give:

  Df $ max [1: 865] & lt; - max (df [1: 865, 2:26])  

I get the maximum max for the variable df in all rows $ max .

You can apply . For example:

  df [, "max"] & lt; - Apply (DF [, 2:26], 1, max)  

Here is a basic example:

  & gt; Df & lt; - data.frame (a = 1: 50, b = rnorm (50), c = rpois (50, 10)) gt; Df $ max & lt; - Applicable (DF, 1, max) & gt; Head (DF, 2) ABC Max 1 1 1.3527115 9 2 2 -0.6469 9 87 20 20 & gt; Tail (DF, 2) ABC Max 49 49 -1.4796887 10 49 50 50 0.1600679 13 50  

Comments