correlation vs lm with two predictors I'm trying to find an equivalent result between cor.test and lm with two predictors.
dat <- data.frame(y=c(1.4, 6.3, 3.2, 1.6, 4.3, 4.5, 8.4, 2.2, 4.2, 6.3, 8.3,
                      2.2, 1.1, 5.3, 2.2, 1.8, 7.5, 1.4),
                  x=c(22.2, 44.3, 13.3, 11.4, 57.3, 54.8, 78.5, 22.6, 45.6,
                      65.4, 14.5, 78.9, 14.4, 67.4, 11.1, 66.8, 91.4, 39.6),
                  d=c(1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0))

x and y are correlated when d == 1
cor.test(dat$y[dat$d == 1], dat$x[dat$d == 1])
    t = 4.5776, df = 7, p-value = 0.002551

How can I reach the equivalent conclusion with lm?
mod <- lm(y ~ x * d, data=dat)


As Dave pointed out, the current regression includes d as a regressor and also specifies an interaction term, cf.
> summary(mod)

Call:
lm(formula = y ~ x * d, data = dat)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.5733 -1.2657 -0.3988  1.2886  5.0506 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept)  2.93777    1.49971   1.959   0.0704 .
x            0.02149    0.02599   0.827   0.4222  
d           -2.27474    2.15567  -1.055   0.3092  
x:d          0.06460    0.04345   1.487   0.1592 

In cor.test you however drop the observations for which d==0. To achieve something similar in a linear regression, try
dat2 <- dat[dat$d==1,1:2]
mod2 <- lm(y ~ x, data=dat2)
> summary(mod2)

Call:
lm(formula = y ~ x, data = dat2)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.2962 -0.8810 -0.3889  0.9786  1.8230 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept)  0.66304    0.83643   0.793  0.45398   
x            0.08609    0.01881   4.578  0.00255 **

Now, the coefficient on x is significant (where the coefficient, as was also mentioned in the comments, is related to, but not the same as the correlation).
