I want to create a new variable with logical operators


#1

He,
I am a new user. I need yours help :slight_smile: I am puting one image.

Capture

I want to create new variable "D" in RStudio.

D is the SUM of number larger than the subject number VARIABLE A( 3,2,4,5) just for ID 1. Also i want to calculate automatically for ID 2,3...

Thank you for answer.


#2

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.


#3

Thank you.

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.

I hope I explained to you

i Capture1