Home > Blockchain >  How to Gather Data with The Same ID from Other Row using R
How to Gather Data with The Same ID from Other Row using R

Time:08-10

I'm using R Studio for data analyzing. I met a dataset that include the same ID but it have different row just like the below example

ID Age Status_Year
1 21 2006
1 22 2007

May I know how to change it or edit it as below or something better than below?

ID Age Status_Year
1 22 2007

CodePudding user response:

Using dplyr you could do

data.frame %>% 
  group_by(ID) %>%
  arrange(Status_Year) %>%
  slice(n())

Note: I added arrange(Status_Year) just to make sure the last row of each "ID" is the latest data.

  •  Tags:  
  • r
  • Related