Below is my data.frame, it contains NA in bonus and increment.
df
name salary bonus increment(%)
AK 22200 120 2
BK 55000 34 .1
JK 12000 400 3
VK 3400 350 15
DK 5699 NA NA
df = structure(list(name = c("AK", "BK", "JK", "VK", "DK"), salary = c(22200L,
55000L, 12000L, 3400L, 5699L), bonus = c(120L, 34L, 400L, 350L,
NA), 'increment(%)' = c(2, 0.1, 3, 15, NA)), .Names = c("name",
"salary", "bonus", "increment(%)"), row.names = c(NA, -5L), class = "data.frame")
basically, I want to keep the names of those people who received the maximum salary, maximum bonus and maximum increase.
what i tried below
df[sapply(df[,2:4],function(x) which.max(x)),1]
output: [1] "BK" "JK" "VK"
But you need a reliable way that can give the same result as the above team, but also takes care of NA. Also, I'm not sure using ,1this is a good thing to display a name column.