How to create means of groups within one column?

,

Hi. I have participant data that I want to analyze. The problem is, that each column contains multiple rows for each participant and since I did three tests at three different time points, there are also three different endings for each time per participant.
Example:

Column 1
A1
A1
A1
A2
A2
A2
A3
A3
A3
B1
B1
B1
B2
B2
B2
B3
B3
C1....etc

I would like to create the mean of each group (A1, A2, A3, B1, ...). I found the dplyr, rowMeans and summarize function but now I'm stuck. What options do I have?

Thank you.

I think we need to see some sample data.
A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here between
```

```

Hi @Barb, welcome to the forum!

I think what you are looking for is the group_by verb...there are plenty of examples on this dplyr page, but specifically:


data %>%
  group_by(col1) %>%
  summarise(groupavg = mean(col2))

Best,
Randy

1 Like

When using group_by() don't forget to ungroup() afterwards, or use .by in summarize()

1 Like

This topic was automatically closed 7 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.