Function to get sum of multiple columns of observations
find_rowwise_sum_multiplecol(the_data, colnames, sumcolname)
the data with added sum
the data where the observations are held
columnname in the data whose sum to be obtianed
name of the new column where sum to be saved
eg_data <- as.data.frame(list(no = c(1, 2, 3, 4),
mark_at_1 = c(12, 7, 23, 45), gender = c("M", "F", "M", "F"),
mark_at_2 = c(12, 34, 89, 45), trialarm = c("1","1","2","2"),
time = c(1,1,2,2), id = c(1, 1, 1, 2)))
find_rowwise_sum_multiplecol(eg_data, c("mark_at_1","mark_at_2"),
"totalmarks")
Run the code above in your browser using DataLab