0

So i looked into a guy's code and i saw these lines of code:

for(i in 1:getOmega(bh_w_f) + 1){
        bh_w_f_qx[i] = (bh_w_f@lx[i] - bh_w_f@lx[i + 1])/bh_w_f@lx[i]

What does @lx[i] mean or do? I tried look it up on the internet but i could not find anything. Any ideas? I want to mention that these lines of code above are the first occurance of @lx[i] or lx[i] or lx alone, so no declaration before. I ran the code and it works, no error given, the function works properly. bh_w_f_qx and bh_w_f are vectors declared before

EDIT : As said in the comments and in the first answer, bh_w_f is actually a S4 object, a lifetable made with function probs2lifetable from https://www.rdocumentation.org/packages/lifecontingencies/versions/1.3.7/topics/probs2lifetable but i could not find what lx wants to be. As i said, it's the first time that lx shows up in the code, with no external files included.

EDIT 2: Found out that the answer is in the returning format from probs2lifetable() function, that returns a lifetable class object which has lxas representing the number of lives at the beginning of age (x). More about it here: https://www.rdocumentation.org/packages/lifecontingencies/versions/1.3.7/topics/lifetable-class Thanks

1 Answers1

2

@ is the symbol used to pull attributes from S4 class objects in R. This syntax can be unusual because most people use S3 as it's simpler than S4. In the case of the code you posted, my guess is that you can get away with thinking of @ as the equivalent of a $ for lists and data frames etc.

dbogdan
  • 66
  • 4