How to print three values at the same time

Hi guys, I have a question about the function print(). Actually, I'm learning how to create a matrix, but I don't find how to print some matrix at the same time.

y <- matrix(1:20, nrow = 5, ncol = 4)
cells <- c(1, 26, 24, 68)
rnames <- c('R1', "R2")
cnames <- c('C1', 'C2')
mymatrix1 <- matrix(cells, nrow = 2, ncol = 2, byrow = TRUE, dimname = list(rnames, cnames))
mymatrix2 <- matrix(cells, nrow = 2, ncol = 2, byrow = FALSE, dimname = list(rnames, cnames))
#of course I can do it with three print functions, but it's not convenient.
#here is the problem, if I separate them with commas (like what I do in Python), it will just return the first matrix.
print(y, mymatrix1, mymatrix2)
#if I use the function c(), it will return a list of numbers, not three matrix.
print(c(y, mymatrix1, mymatrix2))
#if I use the function cat(), it will return a list of numbers and a value NULL(which I don't understand too), not three matrix.
print(cat(y, mymatrix1, mymatrix2))

Thanks in advance for your help and replies! :blush:

1 Like

thank you, it works.

Could you please explain why there is a 'NULL' when I use the function cat()?

cat(), both concatenates and prints, as such the print is redundant, and is trying to print a NULL object.
its equivalent to

a <- NULL
1 Like

thank you👍, it is clear

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.