R - transform upward diagonals to rows
问题 I am given a matrix, data frame or data table. I would like to create a matrix with the upward/reverse diagonals as rows and the remaining cells as NA. I was able to do this. But I think, there should be an easier and simpler solution. So any solutions are appreciated. As an example, suppose I am given the following data.table df1<-as.data.table(matrix(seq(1:100),nrow=20, byrow = TRUE)) > structure(df1) V1 V2 V3 V4 V5 1: 1 2 3 4 5 2: 6 7 8 9 10 3: 11 12 13 14 15 4: 16 17 18 19 20 5: 21 22 23