Ok, so I need a very specific formula for a subset. From the matrix x, I only want to save the elements defined by rows and columns. Then unwanted elements must be replaced with zeros. Example below:
> x <- matrix(c(65,46,52,76,34,345,65,87,12,53),nrow = 5,ncol = 2)
> x
[,1] [,2]
[1,] 65 345
[2,] 46 65
[3,] 52 87
[4,] 76 12
[5,] 34 53
> rows <- c(1,1,2,3,3,4,5)
> cols <- c(1,2,2,1,2,1,2)
magic
> x
[,1] [,2]
[1,] 65 345
[2,] 0 65
[3,] 52 87
[4,] 76 0
[5,] 0 53
Many thanks