I am a beginner in coding in general. I am trying to calculate two parameters from a data frame named a in R. For row i and column j, I am interested in finding:
B = (sum of all values in column j) - a[i,j]
C = (sum of all values in row i) - a[i,j]
For i=1 , j=2, I'm writing:
A = a[1,2]
B = (colSums(a[1:nrow(a),1],na.rm = FALSE, dims = 1) - A)
C = (rowSums(a[1,1:ncol(a)],na.rm = FALSE, dims = 1) - A)
C seems to give correct answer. However, B gives an error:
Error in base::colSums(x, na.rm = na.rm, dims = dims, ...) :
'x' must be an array of at least two dimensions
I have read other threads as well but couldn't find my answer. Do you have any suggestions?