Data Management / Vector Manipulations (In the R language)
The general algorithm I need to implement in R is:
z_i=min(x_i-y_i-a,x_i-b).
I am using i as an index for my z,y, and x vectors. Z is the new vector that I would like to us开发者_运维技巧e in my regression model. If have tried with no success using various types of loops.
I believe you want the pmin
function.
set.seed(21)
x <- runif(10)
y <- rnorm(10)
a <- 1
b <- 0.5
pmin(x-y-a,x-b)
# [1] -0.64701585 -0.24755440 0.19925230 -0.87903259 -0.03799284
# [6] 0.41868340 -1.65560767 -0.32780832 -0.18654580 -0.71345697
精彩评论