create new columns with mean of specific other columns

20 views Asked by At

I'm trying to create 5 new columns in my data frame by calculating the mean of specific already existing columns.

i so far tried the following code:

`data_new2 <- data1 %>%                                   
  data1$chronisch <-apply(data1[,c(22,28,31,25)],1,mean) %>%
  data1$Sozial <-apply(data1[,33],1,mean) %>%
  data1$überforderung <-apply(data1[,c(30,24,27)],1,mean) %>%
  data1$Anerkennung <-apply(data1[,c(26,29)],1,mean) %>%
  data1$Arbeit <-apply(data1[,c(23,32)],1,mean)`

by it give the error message: Fehler in apply(data1[, c(26, 29)], 1, mean) %>% data1$Arbeit <- apply(data1[, : konnte Funktion "%>%<-" nicht finden

But I cannot figure out what the problem is. And yes, deplore is installed and loaded.

Would appreciate ny help!

0

There are 0 answers