How to use collapse

I would like to know how to collapse a data with two ID variables. For some variables, I wanted the first value and for some variables I wanted the last variable. This is a data frame contains around 25 variables and around 600 thousand observations with 64 repetitions. After collapse, depending on the ID variables the data may get reduced to below 200 thousand observations.

Thanks in advance

With regards,
Rajaram S

what is your criteria for this ?
Heres a simple example on iris dataset which has 50 records for each Species, and 4 measurements at each record. for records related to length I take the last record, for width I take the first.


(result <- iris %>% group_by(Species) %>% summarise(
  across(ends_with("Length"),.fns = last),
  across(ends_with("Width"),.fns = first)

Thank you very much for the advice. Will try similar to this code according to my requirement.

Best regards,

I was able to get the first and last values for the required variables. Similar to the first and last values. How to get the count of a variable in the similar way.

Thanks in advance.

With regards,
Rajaram S

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.