adding two vales to one cell of a matrix in R -
i want each cell of matrix/table contain 2 values. e.g 2,1 2,2 2,3 can show me how in r
to have 2 numeric values in single matrix element, can use list.
(m <- as.matrix(list(c(2, 1), c(2, 2), c(2, 3)))) # [,1] # [1,] numeric,2 # [2,] numeric,2 # [3,] numeric,2
then can access values via
m[, 1] # [[1]] # [1] 2 1 # # [[2]] # [1] 2 2 # # [[3]] # [1] 2 3
or
m[1, ][[1]] # [1] 2 1
etc. option use character vector of pasted values
matrix(paste(c(2, 2, 2), c(1, 2, 3), sep = ","), ncol = 1) # [,1] # [1,] "2,1" # [2,] "2,2" # [3,] "2,3"
Comments
Post a Comment