Cannot create a 300 x 300 matrix, console becomes unusable

Hi, I am new to R and I came across an issue I can't deal with.
I am generating knight tour plots based on the following matrix

Mat = matrix(c(DATA), nrow=SIZE, ncol=SIZE, byrow=T)

instead of SIZE I put 300 and instead of DATA I put 90 000 numbers seperated by commas.
However when I try to run it in the console it stops on some number within the matrix and does not finish, leaving me unable to use console as no new line with ">" appears, I can write in it but it does nothing. This issue with console is present even after restaring the Rstudio.

It worked correctly when I tried to make a 100 x 100 matrix. Is there something I don't know about creating matrix ?

Sorry if I gave too little information, I can provide more if specified

My first thought is some kind of memory problem but a quick test
xx <- sample(0:9, 90000, replace = TRUE)
mat <- matrix(xx, nrow = 300, ncol = 300, byrow = TRUE)
seems fine on my lap-top.

Still, what happens if you try with n = 10 000?
BTW I think you only need to specify ncol or nrow.

1 Like

Your test code works fine for me as well, with 10 000 numbers the matrix is created properly and can be used, however this test gave me smth to think about, will let know soon, thx

The console has a line length limit.
Where are you getting the numbers from to paste in? If a file you should tell R to read from the file. Its copy and pasting long strings to console that is foiling you.

1 Like

I see thx ! I get them from the txt file i get from my C# code, can I use this txt file to input data to that matrix ?

Yes
For example if its csv you can use read.csv

1 Like

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.