[R] How to read this data properly?

Greg Snow 538280 at gmail.com
Sat Mar 3 17:24:24 CET 2012


Using the readlines function on your dat string gives the error
because it is looking for a file named "2 3 ..." which it is not
finding.  more likely what you want is to create a text connection
(see ?textConnection) to your string, then use scan or read.table on
that connection.

On Sat, Mar 3, 2012 at 8:15 AM, Bogaso Christofer
<bogaso.christofer at gmail.com> wrote:
> Dear all, I have been given a data something like below:
>
>
>
> Dat = "2 3 28.3 3.05 8 3 3 22.5 1.55 0 1 1 26.0 2.30 9 3 3 24.8 2.10 0
>
> 3 3 26.0 2.60 4 2 3 23.8 2.10 0 3 2 24.7 1.90 0 2 1 23.7 1.95 0
>
> 3 3 25.6 2.15 0 3 3 24.3 2.15 0 2 3 25.8 2.65 0 2 3 28.2 3.05 11
>
> 4 2 21.0 1.85 0 2 1 26.0 2.30 14 1 1 27.1 2.95 8 2 3 25.2 2.00 1
>
> 2 3 29.0 3.00 1 4 3 24.7 2.20 0 2 3 27.4 2.70 5 2 2 23.2 1.95 4"
>
>
>
>
>
> I want to create a matrix out of those data for my further calculations. I
> have tried with readLines() but got error:
>
>
>
>> readLines(Dat)
>
> Error in file(con, "r") : cannot open the connection
>
> In addition: Warning message:
>
> In file(con, "r") :
>
>  cannot open file '2 3 28.3 3.05 8 3 3 22.5 1.55 0 1 1 26.0 2.30 9 3 3 24.8
> 2.10 0
>
> 3 3 26.0 2.60 4 2 3 23.8 2.10 0 3 2 24.7 1.90 0 2 1 23.7 1.95 0
>
> 3 3 25.6 2.15 0 3 3 24.3 2.15 0 2 3 25.8 2.65 0 2 3 28.2 3.05 11
>
> 4 2 21.0 1.85 0 2 1 26.0 2.30 14 1 1 27.1 2.95 8 2 3 25.2 2.00 1
>
> 2 3 29.0 3.00 1 4 3 24.7 2.20 0 2 3 27.4 2.70 5 2 2 23.2 1.95 4': No such
> file or directory
>
>
>
>
>
> Can somebody help to put that data in some workable format?
>
>
>
> Thanks and regards,
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list