0

When i try to work out the mean composite score for 3 variables, I get the exact same answer on every row. I am really new to R so if you know the answer, or have an idea, can you try to explain it simply please?

data <- data %>% 
  group_by(ID) %>% 
  mutate(attract_comp = mean(c(QUESTION_1, QUESTION_2, QUESTION_3), na.rm = T)) %>%
  ungroup()

That's the code I was using and I was trying to get a composite score for QUESTION_1, QUESTION_2 & QUESTION_3 which are the titles for 3 separate columns in my data which kinda looks like: this. Attract_comp is the problem. (ignore opinion_comp).

Nizam
  • 4,569
  • 3
  • 43
  • 60
  • Look like results you might expect if not grouped. First guess might be there is a conflicting variable or package. Could you try running again with a "clean" session? Also, to make reproducible, use `dput()` to provide example data (rather that posting an image). Also show libraries you are using for your session. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a great reproducible example. – Ben Apr 30 '20 at 02:08
  • 1
    Thank you so much! I removed 2 packages hmisc and rmisc and it worked!!! – Jazza K Apr 30 '20 at 14:08

0 Answers0