r - Trouble getting function to return TRUE -
i have code check see if input function valid state. have csv file state column , states care about. made code loop check if input matches of states in list, , if so, return value true.
valid_state <- function(state) { csv <- read.csv("outcome-of-care-measures.csv") (i in range(length(unique(csv$state)))) { if (state == unique(csv$state)[i]) { return (true) } } } all returns null. know valid state entered looking @ csv file myself. think problem starts when try introduce problem don't know why. basically, input possible match 1 state on list, , if does, should return logical vector 1 true.
maybe this. common mistake forget preceeding "1:":
valid_state <- function(state) { csv <- read.csv("outcome-of-care-measures.csv") (i in 1:length(unique(csv$state))) { if (state == unique(csv$state)[i]) { return (true) } } }
Comments
Post a Comment