In Mathematica there is the command Clip[x, {min, max}]
which gives x for min<=x<=max, min for x
Here's a method with nested pmin and pmax setting the bounds:
fenced.var <- pmax( LB, pmin( var, UB))
It will be difficult to find a method that is faster. Wrapped in a function that defaults to a range of 3 and 7:
fence <- function(vec, UB=7, LB=3) pmax( LB, pmin( vec, UB))
> fence(1:10)
[1] 3 3 3 4 5 6 7 7 7 7