Merging rows according to several matching columns

Hello everyone,
I am working in a dataframe that looks something like this:

vims <- data.frame(
  Name_ID = c("a", "a", "a", "b", "b"),
  Date = c(2020, 2020, 2018, 2020, 2028),
  Eye = c("Right", "Left", "Right", "Right", "Right"),
  V1 = c(21, 18, 30, 30, 18)
)

As you can see, the data has an ID and may have several evaluation on different date for that same ID and further it may have different eye evaluations. I am trying to merge rows in order to be arrange by ID and date to obtain rows that contains the ID, the date and all the info for every eye in the same row.

Edit
I found a similar situation here: Merging rows based on values in two columns? - #2 by sergio.costa

But when I run the code I obtained the following error:

>  vims %>%
+   group_by(patient_id, exam_date) %>%
+   summarise(across(c(eye:centralax), sum, na.rm = TRUE))
Error: Problem with `summarise()` input `..1`.
ℹ `..1 = across(c(eye:centralax), sum, na.rm = TRUE)`.
x invalid 'type' (character) of argument
ℹ The error occurred in group 1: patient_id = "EYE00043", exam_date = "17.05.2018".

We need reproducible example (reprex) or at least some usable data.

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.