Lowpar
Lowpar

Reputation: 907

mean function producing same result

the mean function is acting weird, it is constantly producing 0.3880952

H10 <- H10 %>% 
  rowwise() %>% 
  mutate(t10dv = mean(c(fd$DV1_C, fd$DV2_C, 
                        fd$DV3_C, fd$DV4_C), 
         na.rm = TRUE))

head(H10)

            DV1_C           DV2_C         DV3_C           DV4_C     t10dv
            <int>           <int>           <int>           <int>     <dbl>
1               1               0               0               1 0.3880952
2              -1               0               2              -1 0.3880952
3               0               0               0               0 0.3880952
4               0               2               1               1 0.3880952
5              -1              -1              -1              -2 0.3880952
6              -2               0               0               0 0.3880952

Upvotes: 0

Views: 77

Answers (2)

F. Priv&#233;
F. Priv&#233;

Reputation: 11738

What you should do is simply:

H10$t10dv <- rowMeans(H10[c("DV1_C", "DV2_C", "DV3_C", "DV4_C")])

Upvotes: 2

Colin FAY
Colin FAY

Reputation: 5109

Here, your mutate call compute the mean of the concatenation of your four columns (c(fd$DV1_C, fd$DV2_C, fd$DV3_C, fd$DV4_C).

If you need to compute the mean of each column, you need to make 4 calls.

mutate(x = mean(fd$DV1_C), 
       y = mean(fd$DV2_C), ... etc. 

Best

Colin

Upvotes: 0

Related Questions