Re: [R] Reading first line before using read.table()
Thanks so much. The following are the actual lines I used for testing, and they worked. titleline <- readLines("C:/ad/dta/TryRRead/pureCos2.dta", n=1) print(titleline) dta <- read.table("C:/ad/dta/TryRRead/pureCos2.dta", skip = 1, header = TRUE, sep = ",", colClasses = "character") linDta <- linearizeTime(dta); # plot(linDta) spec.pgram(dta[2],log="no",taper=0,xlim=c(0,.05)) -- View this message in context: http://r.789695.n4.nabble.com/Reading-first-line-before-using-read-table-tp4524804p4525000.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Reading first line before using read.table()
try this: > # test data > temp <- tempfile() > writeLines(text = "main title line + a b # table header + 1 2 + 3 4 + 5 6", temp) > input <- file(temp, 'r') # connection for reading > > # read main > main <- readLines(input, n = 1) > rest <- read.table(input, header = TRUE) > close(input) > > main [1] "main title line" > rest a b 1 1 2 2 3 4 3 5 6 > On Sun, Apr 1, 2012 at 8:32 PM, Steve Lianoglou wrote: > Hi, > > On Sun, Apr 1, 2012 at 8:27 PM, Hurr wrote: >> So far I have figured out that the following line >> reads our time series files into R OK. >> dtLs$dta <- read.table("C:/TryRRead/datFiles/JFeqfi4h.rta", header = TRUE, >> sep = ",", colClasses = "character") >> But I have to remove a main-title line so >> that the first line is the column titles line. >> This leads to having two sets of data files around when >> we would rather have just one set. >> How can I read just one line from the file to >> get the main title in before using the read.table() call? > > Not sure I understand correctly, but would something like this do? > > R> title.line <- readLines('file.rta', n=1) > R> dat <- read.table('file.rta', skip=1, header=TRUE, ...) > > -steve > > -- > Steve Lianoglou > Graduate Student: Computational Systems Biology > | Memorial Sloan-Kettering Cancer Center > | Weill Medical College of Cornell University > Contact Info: http://cbio.mskcc.org/~lianos/contact > > __ > R-help@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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@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.
Re: [R] Reading first line before using read.table()
Hi, On Sun, Apr 1, 2012 at 8:27 PM, Hurr wrote: > So far I have figured out that the following line > reads our time series files into R OK. > dtLs$dta <- read.table("C:/TryRRead/datFiles/JFeqfi4h.rta", header = TRUE, > sep = ",", colClasses = "character") > But I have to remove a main-title line so > that the first line is the column titles line. > This leads to having two sets of data files around when > we would rather have just one set. > How can I read just one line from the file to > get the main title in before using the read.table() call? Not sure I understand correctly, but would something like this do? R> title.line <- readLines('file.rta', n=1) R> dat <- read.table('file.rta', skip=1, header=TRUE, ...) -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@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.