hey all greetings hey all am an engineering student...and am trying to learn R i am trying to automate reading a specific type of file...and perform certain functions...but i want to omit lines in the end of the file.. there is an option for skiping the lines before begining...but how can i ask R to read till n-2th or n-3th row...or skip the last 2 or 3 rows while reading... i have files of diff. number of lines...!! i wd be grateful to u if u can help me out of this..!!! thanks in advance Rafi...!! -- View this message in context: http://www.nabble.com/how-to-skip-last-lines-while-reading-the-data-in-R-tp15132030p15132030.html Sent from the R help mailing list archive at Nabble.com.
Henrique Dallazuanna
2008-Jan-28 10:31 UTC
[R] how to skip last lines while reading the data in R
Perhaps: data <- read.table(textConnection(rev(rev(readLines('data.txt'))[-(1:2)]))) will skip the last two lines '-(1:2)' On 28/01/2008, mrafi <confessin at gmail.com> wrote:> > hey all > greetings > > hey all am an engineering student...and am trying to learn R > i am trying to automate reading a specific type of file...and perform > certain functions...but i want to omit lines in the end of the file.. > there is an option for skiping the lines before begining...but how can i ask > R to read till n-2th or n-3th row...or skip the last 2 or 3 rows while > reading... > i have files of diff. number of lines...!! > i wd be grateful to u if u can help me out of this..!!! > thanks in advance > Rafi...!! > > -- > View this message in context: http://www.nabble.com/how-to-skip-last-lines-while-reading-the-data-in-R-tp15132030p15132030.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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Gabor Grothendieck
2008-Jan-28 15:52 UTC
[R] how to skip last lines while reading the data in R
If you don't mind reading it in twice its just: DF <- read.table("xy.dat", header = TRUE, nrow length(readLines("xy.dat")) - 3) tail(DF) # or DF <- read.table("xy.dat", header = TRUE, nrow length(count.fields("xy.dat")) - 3) tail(DF) # or DF <- read.table("xy.dat", header = TRUE, nrow nrow(read.table("xy.dat", header = TRUE)) - 2) tail(DF) On Jan 28, 2008 5:10 AM, mrafi <confessin at gmail.com> wrote:> > hey all > greetings > > hey all am an engineering student...and am trying to learn R > i am trying to automate reading a specific type of file...and perform > certain functions...but i want to omit lines in the end of the file.. > there is an option for skiping the lines before begining...but how can i ask > R to read till n-2th or n-3th row...or skip the last 2 or 3 rows while > reading... > i have files of diff. number of lines...!! > i wd be grateful to u if u can help me out of this..!!! > thanks in advance > Rafi...!! > > -- > View this message in context: http://www.nabble.com/how-to-skip-last-lines-while-reading-the-data-in-R-tp15132030p15132030.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. >