Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How to determine if the value for a variable is the same in a different row for the same id?

$
0
0

I would like to determine if the value for a variable is the same in multiple rows for the same id variable.

The dataset currently looks like:

id   score   date         within_year
1    2       01/20/2016   NA
1    2       04/30/2016   TRUE
1    2       07/23/2016   TRUE
2    3       02/13/2017   NA
2    4       10/20/2017   TRUE
2    4       05/26/2018   FALSE

The within_year variable determines if the score was reported in the same year as the year above for the same id.

I'd like to create a boolean variable that determines if the score reported was the same score reported in the same year for that id (i.e. the boolean variable would read 'true' for id = 1, score = 2, but 'false' for id = 2, score = 3 vs. score = 4 in year 2017.

Does anyone know the easiest way to achieve this with dplyr?


Viewing all articles
Browse latest Browse all 201894

Trending Articles