I have a dataset where I need to calculate a sum-variable of multiple variables. I created a for-loop to perform this one variable at a time:
for (i in 1:nrow(df)) {
df$Q1[i] = sum(df$Q1_A[i], df$Q1_B[i], df$Q1_C[i], na.rm = T)
}
Is there a way to do this for all variables (Q1:Q60) at once? Basically I need a function that adjusts the variable-number from 1 to 2 to 3 to ... to 60. Do I need a for-loop within a for-loop?
Thanks in advance!