1

I am very new to R, and am looking to send each participant individual feedback of their results in my study. To do so, I believe I need to aggregate the dataset by the participant ID number (please correct me if I am on the wrong track!), however am having trouble doing so. I have attempted to combine their answers on each variable/question using rbind and cbind, and then using aggregate() to present each participant's mean score. This is my first time using the aggregate() function, so I am not sure what I have done incorrectly.

mod_4 <- rbind(model_4_tab$Q_Prior, model_4_tab$Q_Field, model_4_tab$Q_Speciality, model_4_tab$Q_Ability_Evidence, model_4_tab$Q_Ability_Belief, model_4_tab$Q_Opinion, model_4_tab$Q_BackedUp, model_4_tab$Q_Consistency, model_4_tab$Q_Trust_Fair, model_4_tab$Q_Trust_Correct, model_4_tab$Q_Credibility, model_4_tab$Q_Value, model_4_tab$Q_Weight)
mod_4 <- cbind(model_4_tab$Q_Prior, model_4_tab$Q_Field, model_4_tab$Q_Speciality, model_4_tab$Q_Ability_Evidence, model_4_tab$Q_Ability_Belief, model_4_tab$Q_Opinion, model_4_tab$Q_BackedUp, model_4_tab$Q_Consistency, model_4_tab$Q_Trust_Fair, model_4_tab$Q_Trust_Correct, model_4_tab$Q_Credibility, model_4_tab$Q_Value, model_4_tab$Q_Weight)

aggregate(mod_4, by = list(
  ID = model_4_tab$ID, 
  Qs = mod_4), 
  FUN = mean, INDICES = model_4_tab$ID, simplify = TRUE, drop = FALSE)

Thank you for your help!

Bronte
  • 29
  • 2
  • 1
    It'd be easier to take you through a good solution if you provided a sample of your data. In any case, I'd recommend utilising the `dplyr` package for this. It may seem a little scary at first, but it'd make this kind of analysis much more straightforward and clean. – Jul Oct 04 '18 at 05:48
  • Also, you are overwriting (not editing/appending) `mod_4` with that `cbind` call. – Jul Oct 04 '18 at 05:51
  • 1
    https://dplyr.tidyverse.org/reference/group_by.html might help. Think about including a minimal reproducible example of your problem to get more specific help >> https://stackoverflow.com/help/mcve – Scransom Oct 04 '18 at 05:56
  • Related [How to sum a variable by group?](https://stackoverflow.com/questions/1660124/how-to-sum-a-variable-by-group) – markus Oct 04 '18 at 06:16

0 Answers0