Calculating functions of truncated and censored normal variables I am trying to understand why lines (1) and (2) give the same result
set.seed(2525); 
n <- 1e6; X <- rnorm(n) 

Lines (1) and (2)
(1) rbind(c(mean(X[X>1]), mean(X*(X>1)), mean(pmax(X-1,0))),
(2) c(dnorm(1)/pnorm(-1), dnorm(1), dnorm(1)-pnorm(-1)))

Result
 [,1]      [,2]       [,3]
[1,] 1.524587 0.2416943 0.08316332
[2,] 1.525135 0.2419707 0.08331547

 A: The first result simulates the mean of a truncated normal distribution with truncation point 1, whose expected value is, from here and standard normality with $\mu=0$, $\sigma=1$,
$$
\mu_T=\frac{\phi(1)}{1-\Phi(1)}=\frac{\phi(1)}{\Phi(-1)},
$$
where the second equality uses symmetry of the standard normal around zero.
The second is the mean of a version of a censored normal distribution with censoring point 1, where, however, the censored values are not replaced with the censoring point but with 0. Hence, the density of the censored distribution can be taken from here.
Since we replace censored values with zeros, they contribute nothing to the expected value, so that we evaluate (see e.g. https://math.stackexchange.com/questions/402215/what-is-int-xe-x2-dx or shorturl.at/eFLO0)
$$
\int_1^\infty x\phi(x)dx=\phi(1)
$$
Had this been "conventional" censoring, we would have looked at mean(X*(X>1)+1*(X<=1)), which, again via here, would have expectation
$$
1\cdot\Phi(1)+\phi(1).
$$
The third problem is basically the same as the second, except that we now evaluate
$$
\int_1^\infty (x-1)\phi(x)dx=\phi(1)-(1-\Phi(1))=\phi(1)-\Phi(-1)
$$
