bobguy 发表于 2013-6-1 20:47 
Here is a simple function you wanted.
funx
One can use lapply / sapply to operate the function on a vector/list as below
funx <- function (x){
if (x <=-1) y=-2
else if (x <=1 ) y=x
else y=2
return (y)
}
x<- as.numeric(c(-0.3,0.8,1,2,3,-3))
y<- as.numeric(lapply(x, funx))
z<- sapply(x, funx, simplify = TRUE, USE.NAMES = TRUE)
y
z