options(scipen = 999)
setwd("C:/Users/irina/Documents/DND/EOHI/eohi1")

# Load the data
exp1_data <- read.csv("exp1.csv")

# Calculate NPast_mean_total as average of NPast_mean_pref, NPast_mean_pers, NPast_mean_val, NPast_mean_life
exp1_data$NPast_mean_total <- rowMeans(exp1_data[, c("NPast_mean_pref", "NPast_mean_pers", "NPast_mean_val", "NPast_mean_life")], na.rm = TRUE)

# Calculate NFut_mean_total as average of NFut_mean_pref, NFut_mean_pers, NFut_mean_val, NFut_mean_life
exp1_data$NFut_mean_total <- rowMeans(exp1_data[, c("NFut_mean_pref", "NFut_mean_pers", "NFut_mean_val", "NFut_mean_life")], na.rm = TRUE)

# Save the updated data
write.csv(exp1_data, "exp1.csv", row.names = FALSE)

# Display summary of the calculated totals
cat("NPast_mean_total summary:\n")
summary(exp1_data$NPast_mean_total)
cat("\nNFut_mean_total summary:\n")
summary(exp1_data$NFut_mean_total)

# Show first few rows to verify calculations
cat("\nFirst 5 rows of calculated totals:\n")
print(exp1_data[1:5, c("NPast_mean_pref", "NPast_mean_pers", "NPast_mean_val", "NPast_mean_life", "NPast_mean_total", 
                       "NFut_mean_pref", "NFut_mean_pers", "NFut_mean_val", "NFut_mean_life", "NFut_mean_total")])
