Last active
October 19, 2018 16:25
-
-
Save mkim0710/0147f49d5d4bfc7b5d0f367a219e647f to your computer and use it in GitHub Desktop.
matrix to integer -void.r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1) | |
m = array(runif(12) * 10, c(3, 4)) | |
dput(m) | |
# > dput(m) | |
# structure(c(2.655086631421, 3.7212389963679, 5.72853363351896, | |
# 9.08207789994776, 2.01681931037456, 8.98389684967697, 9.44675268605351, | |
# 6.60797792486846, 6.2911404389888, 0.617862704675645, 2.05974574899301, | |
# 1.76556752528995), .Dim = 3:4) | |
m2 = as.integer(m) | |
dput(m2) | |
# > dput(m2) | |
# c(2L, 3L, 5L, 9L, 2L, 8L, 9L, 6L, 6L, 0L, 2L, 1L) | |
cbind(as.vector(m), m2) | |
# > cbind(as.vector(m), m2) | |
# m2 | |
# [1,] 2.6550866 2 | |
# [2,] 3.7212390 3 | |
# [3,] 5.7285336 5 | |
# [4,] 9.0820779 9 | |
# [5,] 2.0168193 2 | |
# [6,] 8.9838968 8 | |
# [7,] 9.4467527 9 | |
# [8,] 6.6079779 6 | |
# [9,] 6.2911404 6 | |
# [10,] 0.6178627 0 | |
# [11,] 2.0597457 2 | |
# [12,] 1.7655675 1 | |
dim(m2) = dim(m) | |
dput(m2) | |
# > dput(m2) | |
# structure(c(2L, 3L, 5L, 9L, 2L, 8L, 9L, 6L, 6L, 0L, 2L, 1L), .Dim = 3:4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment