[R] Ignore text when reading data

Remko Duursma remkoduursma at gmail.com
Thu Jan 29 04:28:05 CET 2009


# replace this bit, replace it with your file name
myfile <- textConnection(
"Time    out1
Sec     mm
0.82495117      -0.020977303
1.3554688       -0.059330709
1.826416        -0.021419302
2.3295898       -0.051521059
2.8347168       -0.020661414


Time    out1
Sec     mm
3.8679199       -0.000439643
4.3322754       -0.063477799
4.8015137       -0.024581354
5.3286133       -0.067487299
5.8212891       -0.011978489")

# which lines not to read
notread <- c(which(r==""),grep("Time ",r),grep("Sec ",r))

# read the data as text
mydata <- r[setdiff(1:length(r),notread)]

# make it into a dataframe (I think this can be done prettier, but whatever)
z <- paste(mydata, collapse="\n")
read.table(textConnection(z))


greetings
Remko

-------------------------------------------------
Remko Duursma
Post-Doctoral Fellow

Centre for Plant and Food Science
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753

Dept of Biological Science
Macquarie University
North Ryde NSW 2109
Australia

Mobile: +61 (0)422 096908



On Thu, Jan 29, 2009 at 11:45 AM, beyar <bxx at mailinator.com> wrote:
>
> Hi,
> I have tab delimited text files containing numerical data,
> like below, but many more columns.
>
> As you can see, the first few lines are heading and file data.  I need to
> skip these lines.  2 lines above where the numbers start is what I want to
> use as my header rows.  I then want to ignore the next line (containing
> units) and start importing data.
>
> The header row repeats.  i want to ignore the blank rows and text in the
> data and then continue reading.  Is there an easy way to do this?
>
> thanks
> Beyar
>
>
> -------------------------
> main data file - file 1
> by mr x
> etc
>
>
> Time    out1
> Sec     mm
> 0.82495117      -0.020977303
> 1.3554688       -0.059330709
> 1.826416        -0.021419302
> 2.3295898       -0.051521059
> 2.8347168       -0.020661414
>
>
> Time    out1
> Sec     mm
> 3.8679199       -0.000439643
> 4.3322754       -0.063477799
> 4.8015137       -0.024581354
> 5.3286133       -0.067487299
> 5.8212891       -0.011978489
>
> -----------------------------------------------
>
> --
> View this message in context: http://www.nabble.com/Ignore-text-when-reading-data-tp21718709p21718709.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list