I have a matrix, and I am attempting to add a column at the end with the row sums, and then dividing the rows by the row sums, conditional on the row sum being greater than 100. This is what I have so far:
row.sums <- rowSums(a)
a <- cbind(a, row.sums)
This gives me the initial matrix I want, with a column at the end with the row Sums. The following code is what I have attempted for the second step:
a[(a[,dim(a)]>100)] <- dtm/row.sums
This gives me an error saying that the size of the vector I want to replace does not match the vector I want to replace it with. What am I doing wrong here? Sorry if this is a very basic question, I am pretty new to R/ coding in general.