[R] help usin scan on large matrix (caveats to what has been discussed before)

Martin Tomko martin.tomko at geo.uzh.ch
Thu Aug 12 13:34:53 CEST 2010


Hi Peter,
thank you for your reply. I still cannot get it to work.
I have modified your code as follows:
rows<-length(R)
cols <- max(unlist(lapply(R,function(x) length(unlist(gregexpr(" 
",x,fixed=TRUE,useBytes=TRUE))))))
c<-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1),rows-1)), skip=1)
m<-matrix(c, nrow = rows-1, ncol=cols+1,byrow=TRUE);

the list c seems ok, with all the values I would expect. Still, 
length(c) gives me a value = cols+1, which I find odd (I would expect 
=cols).
I thine repeated it rows-1 times (to account for the header row). The 
values seem ok.
Anyway, I tried to construct the matrix, but when I print it, the values 
are odd:
 > m[1:10,1:10]
       [,1] [,2]       [,3]       [,4]       [,5]       [,6]       [,7]
  [1,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [2,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [3,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [4,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [5,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [6,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [7,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [8,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
  [9,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 
Integer,15
[10,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15
....

Any idea where the values are gone?
Thanks
Martin

Hence, I filled it into the matrix of dimensions

On 8/12/2010 12:24 PM, peter dalgaard wrote:
> On Aug 12, 2010, at 11:30 AM, Martin Tomko wrote:
>
>    
>> c<-scan(file=f,what=list(c("",(rep(integer(0),cols)))), skip=1)
>> m<-matrix(c, nrow = rows, ncol=cols,byrow=TRUE);
>>
>> for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying "integer(0)" correct?
>>      
> No. Well, integer(0) is just superfluous where 0L would do, since scan only looks at the types not the contents, but more importantly, what= wants a list of as many elements as there are columns and you gave it
>
>    
>> list(c("",(rep(integer(0),5))))
>>      
> [[1]]
> [1] ""
>
> I think what you actually meant was
>
> c(list(NULL),rep(list(0L),5))
>
>
>
>    
>> And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen that some sparse matrix packages produce different looking outputs, which would not be appropriate.
>>
>> Thanks
>> Martin
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>      
>    


-- 
Martin Tomko
Postdoctoral Research Assistant

Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland

email: 	martin.tomko at geo.uzh.ch
site:	http://www.geo.uzh.ch/~mtomko
mob: 	+41-788 629 558
tel: 	+41-44-6355256
fax: 	+41-44-6356848



More information about the R-help mailing list