[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 21:57:27 CEST 2010


I did. Did not work. Did you try your code? The matrix did not result into
integer numbers as expected. MY approach resulted in a correct scan
result, at least.

M.
> Martin Tomko wrote:
>> Hi Peter,
>> apologies, too fast copying and pasting.
>> So, here is the explanation:
>> f<-"C:/test/mytab.txt";
>> R<-readLines(con=f);
>>
>> where mytab.txt is a table formatted as noted in previous post (space
>> delimited, with header, rownames, containing integers).
>>
>> Now, my understandign of scan was that I have to specify the FULL number
>> of values in it (examples specify things like 200*2000 for a matrix
>> etc). That's why I thought that I need to do cols*rows as well. Avoiding
>> the first line with headers is simple, avoiding the first column is not
>> - hence my questions.
>> Sorry, the corrected, matching parentheses are here - why did the
>> previous execute is a wonder...
>> c<-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1),
>> skip=1)
>> here, my reasoning was:
>>
>> * c(list(NULL),rep(list(0L),cols-1)) specifies a template for any line
>> (first elelement to be ignored => NULL, it is a string in the table
>> specified, and then a repetition of integers - I am still not sure how
>> you derived 0L, and what it means and where to find a doc for that.);
>> * the previous needs to be repeated rows-1 times, hence
>> what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1)
>>
>> I do nto understand the following:
>>
>>   You need an unlist(c). And more than likely NOT byrow=TRUE. However, I
>> think do.call(cbind,c) should do the trick more easily.
>>
>> what will unlist(c) do; why should it not be bywrow=TRUE, and how would
>> you go about integrating do.call(cbind,c) with matrix. Apologies to
>> naive questions, I am a newbie, in principle.
>>
>
> At this point I think you need to actually try my suggestions, and maybe
> read the documentation again. Explaining how you have misunderstood the
> documentation is not going to help...
>
> --
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>



More information about the R-help mailing list