how to calculated average number of elements that has same value as another element

hi, i'm relatively new to r and rstudio but i'm having a difficult problem that i need help with. i have a set of data like in the picture. what i'm trying to do is to get the average number of different y that has same value of x as another specific y since the set is much longer and beside x that reoccurring, y also repeat itself. for example in the 1st row we have y = 1203, there are 4 'others y' with same x, later in the list 1203 will appear again and might have different x with different number of 'other y' with the same new x value, and i need to calculated the average of that number. so far i still havent figure out how to go about this please help

You will need a combination of dplyr::group_by() and dplyr::sumarise(), keeping in mind that to calculate average you need the function mean(), which might be somewhat acquired taste for users of Excel or SQL (where the function is called AVG() from average).

In this context you might find the chapter 5 of the R4DS book interesting read: 5 Data transformation | R for Data Science

thank you i'll definitely check it out

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.