How do I use an apply function in R to find the maximum of a variable for subgroups

 salary <- data.frame(name=c("Kay","Dave","Jon","Jenny","Jim","Eve","Ed"),
 salary=c(60000, 100000, 50000, 80000, 30000, 40000, 20000),

I am able to filter a female data frame with

femaleFiltered <- salary[ which(salary$gender=='F'), ]

and I am trying to use

getMaxSal1 <- function(x) {


but get error "Error in x$salary: $ operator is invalid for atomic vectors"

Read more here:

Content Attribution

This content was originally published by Rohit Goswami at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: