My data looks like:
head(myframe)
id fwt_r fwt_l
[1,] 101 72 52
[2,] 102 61 48
[3,] 103 46 49
[4,] 104 48 41
[5,] 105 51 42
[6,] 106 49 35
I want to select the greater of the two values among fwt_r and fwt_l. I want the output like:
72
61
49
48
51
49
Kindly help me out. Thanks!
Maximum value of a column in R can be calculated by using max() function. Max() Function takes column name as argument and calculates the maximum value of that column. Maximum of single column in R, Maximum of multiple columns in R using dplyr.
To pick out single or multiple columns use the select() function. The select() function expects a dataframe as it's first input ('argument', in R language), followed by the names of the columns you want to extract with a comma between each name.
You are looking for the 'pmax' function
Just run this:
pmax(myframe$fwt_r, myframe$fwt_l)
pmax means 'parallel maxima' (or vectorized)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With