2
Hello, I have the following code
M <- matrix(data = c(1,2,3,4,5), nrow = 5, ncol = 5, T)
It produces the following output:
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 1 2 3 4 5
[3,] 1 2 3 4 5
[4,] 1 2 3 4 5
[5,] 1 2 3 4 5
I want the array to be created in a way that uses the values of the given array as date, but not to repeat the array afterwards, but to complete the values not provided with NA
, being as follows:
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] NA NA NA NA NA
[3,] NA NA NA NA NA
[4,] NA NA NA NA NA
[5,] NA NA NA NA NA
I know you can do this by creating a matrix with data = NA
and then loop the matrix, but wanted to know a faster and more efficient way to do.