trim_val function

trim vector to lower or upper value