> 1:15
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
> matrix(1:15,ncol=3)
[,1] [,2] [,3]
[1,] 1 6 11
[2,] 2 7 12
[3,] 3 8 13
[4,] 4 9 14
[5,] 5 10 15
[,1] [,2] [,3]
[1,] 1 6 11
[2,] 2 7 12
[3,] 3 8 13
[4,] 4 9 14
[5,] 5 10 15
> diff(matrix(1:15,ncol=3))
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
[4,] 1 1 1
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
[4,] 1 1 1
> c(1:7,NA,9:15)
[1] 1 2 3 4 5 6 7 NA 9 10 11 12 13 14 15
> w <- matrix(c(1:7,NA,9:15), ncol=5)
> w
[,1] [,2] [,3] [,4] [,5]
[1,] 1 4 7 10 13
[2,] 2 5 NA 11 14
[3,] 3 6 9 12 15
> v <- as.vector(w)
> v[is.na(v)]
[1] NA
> v[is.na(v)] <- 8
> matrix(v,ncol=dim(w)[2])
[,1] [,2] [,3] [,4] [,5]
[1,] 1 4 7 10 13
[2,] 2 5 8 11 14
[3,] 3 6 9 12 15
> w <- matrix(v,ncol=dim(w)[2])
> w
[,1] [,2] [,3] [,4] [,5]
[1,] 1 4 7 10 13
[2,] 2 5 8 11 14
[3,] 3 6 9 12 15