0

I have a table with 2 columns.
Type: 1 or 2 or 3 or 4
Data: corresponding data (there are multiple data for each type)

Now I want to create a third column that contains means of data each type i.e., all the rows with type 1 have the same mean value. I think I should do it with mutate function but not sure how to proceed.

data %>% mutate(meanData = ifelse(...))

Can somebody help?

Thank you in advance.

animus
  • 77
  • 6

1 Answers1

0

We can do a group by operation

library(dplyr)
data <- data %>%
        group_by(Type) %>%
        mutate(meanData = mean(Data))
akrun
  • 874,273
  • 37
  • 540
  • 662