I have a dataset in R
as follows.
dat <- as.data.frame(t(cbind(c(5,10,15,20),c(10,20,30,40),c(50,100,150,200),c(200,400,600,800))))
dat
How can create a new dataframe dat_new
that each row has been divided by the value in the main diagonal of the corresponding row? The final results must be:
> dat_new
1 1 5 3 4
2 0.5 1 1.5 2
3 0.33 0.66 1 1.33
4 0.25 0.5 0.75 1