If conditional statement Error: unexpected '}' in " }" in R programming :     rankhospital <- function(state, outcome, num = "best"){
          ## Read outcome data
          data <- read.csv("outcome-of-care-measures.csv", colClasses = "character")
          hospital <- data.frame(data[,2], #name 
                                 data[,7], #state
                                 data[,11], #heart attack
                                 data[,17], # heart failure
                                 data[,23], stringsAsFactors = FALSE) #pneumonia
          colnames(hospital) <- c("name", "state", "heart attack", "heart failure", "pneumonia")
          ## Check that state and outcome are valid
          if (!state %in% hospital[, "state"]) { stop('invalid state')} 
          else if (!outcome %in% c("heart attack", "heart failure", "pneumonia")){ stop('invalid outcome')}
          else if (is.character(num)){
            if (num == "best") {
              chosen_state <- hospital[which(hospital[, "state"] == state), ] #select the state
              chosen_outcome <- chosen_state[ , outcome] #select the outcome from the state
              best_outcome <- chosen_state[which(chosen_outcome == min(chosen_outcome, na.rm = TRUE)),]["name"]
              best_hospital <- best_outcome[order(best_outcome)][ , "name"] #sort
              best_hospital
            } 
            else (num == "worst") {
              chosen_state <- hospital[which(hospital[, "state"] == state), ] #select the state
              chosen_outcome <- chosen_state[ , outcome] #select the outcome from the state
              best_outcome <- chosen_state[which(chosen_outcome == max(chosen_outcome, na.rm = TRUE)),]["name"]
              best_hospital <- best_outcome[order(best_outcome)][ , "name"] #sort
              best_hospital
            } 
          else (is.numeric(num)) {
            if (num =< length(hospital$name){
              chosen_state <- hospital[which(hospital[, "state"] == state), ] #select the state
              chosen_outcome <- as.numeric(chosen_state[ , outcome]) #select the outcome from the state
              chosen_state[which(sort(chosen_outcome)) == num, ][,"name"]
         
           } 
            else (num > length(hospital$name) { stop('NA')}
           
         } 
          
        }

When i run the code, it throws " Error: unexpected '}' in "}" " where 
else (num == "worst") part, so if i change this if from else, it'll go down and throws me an error again at else (is.numeric(num)). What have i done it wrong with this code? I thought If statement goes like this
--------------------
If  
else if
else if 
else
--------------------
If  
else if
  if
  else
else if
  if
  else
else
  if
  else
-----------------

Thanks in advance!
