Hi there, and welcome to community.rstudio.com! It's a little difficult to understand what your goal is - should D be calculated for every value of A, including those that exceed 5? Have you attempted writing any code to calculate D?

A little bit more context and explanation will help us understand your needs. Instead of posting an image, can you please add a reprex (reproducible example) to your post? This will ensure we're all looking at the same data and code. A guide for creating a reprex can be found here.

All i did was export excel data in R.
Maybe for one ID easier to explan what i want.
In the first step just for ID1 i want to calculate:
for each cell A(3,2,4,5), calculate sum of number larger then select number. So first selected number is 3, larger numbers than 3 is 4 and 5 sum is 9. Then calculate especially for number 2, 4, 5.