Re: [R] converting an ASCII file to a matrix

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Wed 11 May 2005 - 02:23:07 EST

Michael Graber wrote:
> Dear R-WinEdit users,

  1. What is an R-WinEdit user?
  2. I guess you mean R-WinEdt (without an i) implying the plug-in for the WinEdt editor? WinEdit is another editor that does not support R very closely, AFAIK.
  3. The following questions are completely unrelated to any editor, so why do you ask only a very small (empty?) subset of the R community?

> I have a simple question, but somehow I cannot find the answer even
> though I tried a lot!
>
> I have an unstructured ASCII-file and I want to import it into a matrix
> m in R, so that every character is defined by m[i;j]. The rows are not

d) What does m[i;j] mean? If we are speaking R, I guess you mean m[i,j]?

> of the same length.
>
> The file looks like the following shortened abstract example:
>
> name: xxxxx xxxx
> age: 9.9.99
> record number: 999
> title: xxxxx xxxx xxx
> keywords: xxx xx
>
> "white space"
>
> name: yyyy yyyyyyyyyyyy
> age: 8.8.88
> record number: 8
> title: yyyy yy yyyy
> keywords: yyyyyyyyyyy yyyyyyyy yyy
>
> "white space"
>
> The result should be for example: m[1;1]=n

So what aboutreading all lines, and storing separate characters as vectors in a list using strsplit().

   L <- strsplit(readLines(filename), "")    L[[i]][j]

A matrix seems to be the wrong way with unequal line lengths.

Uwe Ligges

> I would be very grateful for your help!
>
> Michael Graber
> michael.graber@mail.uni-wuerzburg.de
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 11 02:29:52 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:41 EST