I want to calculate the mean of a subset for different participants in a row. I tried a lot of things but there are errors everytime. What is a better approach? I listed below what I tried so far
# calculate positive subscale via mean
positive_subscale <- df_wide_final %>%
select(GAAIS_Pos_item_1, GAAIS_Pos_item_2, GAAIS_Pos_item_3, GAAIS_Pos_item_4, GAAIS_Pos_item_5, GAAIS_Pos_Item_6, GAAIS_Pos_Item_7, GAAIS_Pos_Item_8, GAAIS_Pos_Item_9, GAAIS_Pos_Item_10, GAAIS_Pos_Item_11, GAAIS_Pos_Item_12)
pos_num <- lapply(positive_subscale, as.numeric)
pos_mean <- rowMeans(pos_num[drop = FALSE])
positive_subscale %>% summarise_each(funs(mean))
mean_pos <- sapply(Filter(is.numeric, positive_subscale), mean)
pos_character <- as.character(positive_subscale)
pos_numeric <- as.numeric(pos_character)
mean <- aggregate(positive_subscale$GAAIS_Pos_item_1, mean)
pos_numeric <- as.numeric(unlist(positive_subscale))
rowMeans(pos_numeric, na.rm = TRUE)
gemiddelde_pos <- mean(strtoi(positive_subscale[1, ]))
lapply(positive_subscale, gemiddelde_pos)
rowMeans(strtoi(positive_subscale)[1, , drop = FALSE])
I tried different approaches to calculate the mean for every participant, but nothing worked so far