In R I am having a data frame with states and their populations for various years. I want to build a function which finds the highest population in a given year and returns the corresponding state name. I know how to retrieve the max population, but I don't know how to use that to look up the corresponding state name. Here's my code to find the max population:
max(dfStates$Jul2011)
Now, I am having the following:
lotsOfPeeps<-function(dfStates){
highestPop<-max(dfStates$Jul2011)
return(highestPop)}
So, when I executed the lotsOfPeeps(dfStates) function right now it will only returns the highest population. How would I continue to it to reclaim the state name?