# Create some fake data
set.seed(14)
df = data.frame(power = sample(seq(15,31,0.5),30, replace=TRUE),
total= sample(c(0,1,2,3,7:11), 30, replace=TRUE),
found=sample(c(0:2,7:9), 30, replace=TRUE))
df$total[c(5,9)] = NA # Add some missing data
# Minimum of `power` at maximum of `total`
min(df$power[df$total==max(df$total, na.rm=TRUE)], na.rm=TRUE)
[1] 17.5
If you want to see all the values of power
at the maximum value of total:
df$power[df$total==max(df$total, na.rm=TRUE)]
[1] NA NA 17.5 25.0 30.5 31.0
You can use the which
function if you don't want missing values returned:
df$power[which(df$total==max(df$total, na.rm=TRUE))]
[1] 17.5 25.0 30.5 31.0
which
returns only the row indices for which the logical test is TRUE
, while the logical test alone returns a value of TRUE
, FALSE
, or NA
for every single row.