mercredi 21 octobre 2020

Creating a new column in R based off certain criteria

so I have a dataset, df, that looks like this

Customer Spending
abc      $10
abc      $11
123      $5
123      $10
456      $9
456      $2

I want to create a new column, lets name this <$20 that would return the name of the customer whose sum of spending is less than $20 and return a null value if the customer spent over $20.

I would want the result to appear like this

Customer Spending <$20k
abc      $10       null
abc      $11       null
123      $5        123
123      $10       123
456      $9        456
456      $2        456

Any idea on how to go about this? I feel like this should be basic, but I am struggling. Thanks!

Aucun commentaire:

Enregistrer un commentaire