[R] read a file into a matrix

David Winsemius dwinsemius at comcast.net
Fri Nov 20 19:45:14 CET 2009


On Nov 20, 2009, at 1:01 PM, Peng Yu wrote:

> On Sat, Nov 21, 2009 at 11:55 AM, Steve Lianoglou
> <mailinglist.honeypot at gmail.com> wrote:
>>> read.delim gives me a data.frame. Is there a function that can  
>>> return
>>> the result in a matrix rather than data.frame?
>>
>> m <- as.matrix(read.delim(..))
>
> I knew this approach. But this takes an extra step. Is there a command
> that read a file directly into a matrix?

You can wrap matrix() around a scan() call. An example might prompt  
more specifics.

You also could easily modify read.delim (which is after all a wrapped  
scan call) to create a matrix rather than a dataframe.

-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list