I have a df ( my_df : n by m ) and also a matrix ( my_mat : n by m again ).
I want to change the value of my_df[j,i] if my_mat[j,i] is not zero, and leave it as is, if my_mat[j,i] is zero.
then I want to return the index of the column of my_df which contains the highest value in that row, in a grp column.
for(j in 1:nrow(my_df)){
for(i in 1:nclo(my_df){
if(my.mat[j,i]!=0)
{my.df[j,i] <- (my.mat[j,i])/(crossprod(my.vec,my.mat[j,]))
}
my.df$grp[j] <- which.max(my.df[j,])
}
}
I notice, my code does not leave the my.df[j,i] untouched if my.mat[j,i] is zero. how can I solve this?