1

I have a dataset like following:

 0 0 0 0 0 0 54077 184965 81.25 54266 184776 81.25 65130 199986 82.1705426356589 65513 199600 82.1705426356589 

those data were seperated by 2 blank lines. So when I use gnuplot to draw a dotplot, they will think those are seperated data in one file. How to do the same thing in R?? Because for each such dataset, I will have two points connected by lines. (eg, [5077,184965] connect to [54266, 199600])

Than you very much!

3 Answers 3

2

Two thoughts:

  1. If they are all in the same format, then set the blank.lines.skip argument of read.table/read.csv to FALSE instead of its default TRUE. Then you get a data.frame that has blank lines in it which you can split on.

  2. If they are not all in the same format, then you can use the skip argument of those same commands to pull out only certain lines of the input file.

Sign up to request clarification or add additional context in comments.

Comments

2

Worst case scenario, you have to use readLines with n=1 to read a line at a time, splitting with strsplit, and collecting each data set in a list, looking for the separator (blank lines) before starting a new element of your list.

But you only need do that if gsk3's solutions fail because your dataset is a bit more unstructured...

Comments

1

You can also read the file into memory,

> buffer <- readLines ("tmp/file") > buffer [1] "0 0 0" "0 0 0" [3] "" "" [5] "54077 184965 81.25" "54266 184776 81.25" [7] "" "" [9] "65130 199986 82.1705426356589" "65513 199600 82.1705426356589" 

delete or process (e.g. derive measurement number, data set name, ...) all lines that somehow do not belong to the part of the file with the data tables:

> buffer <- buffer [nzchar (buffer) > 0L] > buffer [1] "0 0 0" "0 0 0" [3] "54077 184965 81.25" "54266 184776 81.25" [5] "65130 199986 82.1705426356589" "65513 199600 82.1705426356589" 

and finally use read.table on the modified buffer:

> read.table (textConnection (buffer)) V1 V2 V3 1 0 0 0.00000 2 0 0 0.00000 3 54077 184965 81.25000 4 54266 184776 81.25000 5 65130 199986 82.17054 6 65513 199600 82.17054 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.