# Interpreting score function in Cox model

Several sources state that the score function for the likelihood of a cox model is

$$\dfrac{\partial{}l(\beta)}{\partial\beta}=\Big(X_{i}\delta_i^T-\sum\limits_{i=1}^{n}\delta_i\dfrac{\sum\limits_{j\in R(t_i)}^{} X_{j} e^{X_j'\beta}}{\sum\limits_{j\in R(t_i)}^{} e^{X_j'\beta}}\Big),$$

Where $X$ represents the covariates matrix ${x_1, x_2}$, $\delta_i$ is a vector of censor indicators, $\delta_i = {1,0,1..}$

I am little confused with the second portion of the score function ,

$$.....\sum\limits_{i=1}^{n}\delta_i\dfrac{\sum\limits_{j\in R(t_i)}^{} X_{j} e^{X_j'\beta}}{\sum\limits_{j\in R(t_i)}^{} e^{X_j'\beta}}\Big),$$

specifically summing over riskset $R(t_i)$,...specifically $\dfrac{\sum\limits_{j\in R(t_i)}^{} ...}{\sum\limits_{j\in R(t_i)}^{}...},$ If this is my dataset below

   t    C         X2        X3
11  1  -0.055813  0.120604
13  1   0.208699  0.454470
16  1   0.074084 -0.041499
18  0  -0.460969 -0.459859
21  1   0.184053 -0.277739
22  0   0.111372 -0.473904


I am assuming, at time, $t_1$ , $X_1= {-0.055813, 0.120604}$ , at time $t_2$, $X_2= { 0.208699, 0.4554470}$ ...so on and implement this as

#Beta
B1=1;  B2=2
B =matrix(c(B1,B2))

#X
X <- as.matrix(cbind(df$X2, df$X3))

#Censoring
C <- as.matrix(df\$C)

numertr   <-  rowSums(t(X)%*%exp(X%*%B)%*%t(C))
denomtr   <-  as.numeric(sum(exp(X%*%B)))
part2     <- numertr/denomtr


What I am missing here ? Where am i going wrong ? Any advice is much appreciated.