I am trying to create a 256*256 matrix in R. Simple task I thought… If I create the data such that
aa=1:65536
z = matrix(bb,nrow=256,ncol=256,byrow=T)
I have the matrix I want e.g.
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
and so on. However, I am not creating the “aa” data but reading it instead such that
aa = read.table("myfile.txt",header=F)
> aa[c(1:10),]
[1] 1513.708 1513.971 1514.067 1513.971 1513.875 1513.622 1513.524 1513.578 1513.577 1513.481
When I read aa, the data looks fine but when I try and turn it into a matrix, the matrix reads as
[,1] [,2] [,3] [,4] [,5]
[1,] Numeric,65536 Numeric,65536 Numeric,65536 Numeric,65536 Numeric,65536
and so on. Any idea why this is happening?
Thank you very much for your help!
Note this paragraph in the ‘Memory usage’ section of
?read.table:Granted, your 256×265 matrix isn’t large but
scanstill seems more appropriate.