mercredi 3 février 2021

Calculate average on 2 column value and apply condition to create new variable in R. (Help from Excel)

I am working on a dataset (which has more than 3000 rows), here is my simple explanation. I am looking to solve in R.

Please refer to the attached pic,

based on A, I want to create a new variable B. Now, B1 "Low" is... if A1 > AVG(A2, A3). So, here AVG of A2 and A3 is (2+5)/2 = 3.5, and hence the condition for A1 is lower than AVG of A2 and A3. So new variable answer B1 is "Low".

Now, we can easily solve this in Excel for 3000 rows (by creating a function and drag and drop button). But, I need help to create a new variable B in R.

enter image description here

Aucun commentaire:

Enregistrer un commentaire