0

Does anyone know how to neatly average across item ID for multiple topics? Say I have five to fifteen responses (& I won't know how many unless I check them) for ID1-ID100, for which I want averages across six dimensions – how do I do that?

I have looked at rowMeans() and colMeans() and I’m sure one of those could easily solve this, but practically I somehow don’t get it.

Here is an example of what I mean (i.e., this is what I have):

Item ID Taste Colour
ID1 4 3
ID1 4 3
ID1 2 2
ID1 4 3
ID2 3 2
ID2 3 4
ID2 2 3
ID3 4 2
ID3 3 2
ID3 4 3
ID3 3 4

And this is what I want:

Item ID Taste Colour
ID1 3.5 2.75
ID2 2.67 3
ID3 3.5 2.75

(I'm sorry that the second table isn't showing properly when published, it works fine in the draft)

Maël
  • 45,206
  • 3
  • 29
  • 67
Bommby
  • 35
  • 4
  • You seem to want a mean by group. Check the answers in the link that I added. [This](https://stackoverflow.com/a/74612213/13460602) is the latest `dplyr` answer, and [this](https://stackoverflow.com/a/9723314/13460602) the way to go in base R – Maël Mar 07 '23 at 16:06
  • `df %>% summarise(across(c(Taste, Colour), mean), .by = "Item ID")` – Maël Mar 07 '23 at 16:07
  • That didn't work... it averaged all IDs over each other and left only one singular value for Taste and Colour, and the Item ID itself (which I'd like to keep as one column) is also gone. I had already seen the other question, but I still couldn't figure out how to get it to work, thank you though! – Bommby Mar 07 '23 at 16:25
  • `df %>% group_by(Item ID) %>% summarise(across(c(Taste, Colour), mean))` – Maël Mar 07 '23 at 16:28
  • Thank you SO MUCH! That is exactly what I needed, I really appreciate it! – Bommby Mar 07 '23 at 16:29

0 Answers0