I have a file named "test.csv" with the following 3 lines: %y-%m-%d;VALUE 1999-01-01;100 2000-12-31;999 > read.table("test.csv", header = TRUE, sep = ";") delivers: X.y..m..d VALUE 1 1999-01-01 100 2 2000-12-31 999 I would like to see the following ... %y-%m-%d VALUE 1 1999-01-01 100 2 2000-12-31 999 Note, > readLines("test.csv", 1) delivers [1] "%y-%m-%d;VALUE" Is this possible ??? Thanks DW
?read.table The documentation has the parameter 'check.names'. On 2/13/06, Diethelm Wuertz <wuertz@itp.phys.ethz.ch> wrote:> > > > I have a file named "test.csv" with the following 3 lines: > > %y-%m-%d;VALUE > 1999-01-01;100 > 2000-12-31;999 > > > > read.table("test.csv", header = TRUE, sep = ";") > > delivers: > > X.y..m..d VALUE > 1 1999-01-01 100 > 2 2000-12-31 999 > > > I would like to see the following ... > > %y-%m-%d VALUE > 1 1999-01-01 100 > 2 2000-12-31 999 > > > Note, > > > readLines("test.csv", 1) > > delivers > > [1] "%y-%m-%d;VALUE" > > > Is this possible ??? > > > Thanks DW > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve? [[alternative HTML version deleted]]
You can do it manually by reading in the headers separately: headers <- read.table(test, header = FALSE, nrow = 1, sep = ";", as.is = TRUE) read.table(test, header = FALSE, skip = 1, sep = ";", col.names = headers) On 2/13/06, Diethelm Wuertz <wuertz at itp.phys.ethz.ch> wrote:> > > I have a file named "test.csv" with the following 3 lines: > > %y-%m-%d;VALUE > 1999-01-01;100 > 2000-12-31;999 > > > > read.table("test.csv", header = TRUE, sep = ";") > > delivers: > > X.y..m..d VALUE > 1 1999-01-01 100 > 2 2000-12-31 999 > > > I would like to see the following ... > > %y-%m-%d VALUE > 1 1999-01-01 100 > 2 2000-12-31 999 > > > Note, > > > readLines("test.csv", 1) > > delivers > > [1] "%y-%m-%d;VALUE" > > > Is this possible ??? > > > Thanks DW > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Thanks a lot that works fine! Next problem, if I would have my own package, and the file "test.csv" would be located in the data directory How to use the function data to get > data(test) resulting in: > test %y-%m-%d VALUE 1 1999-01-01 100 2 2000-12-31 999 Again Thanks in advance Diethelm Wuertz Phil Spector wrote:> Look at the check.names= argument to read.table -- you want to set it > to FALSE. But rememeber that you'l have to put quotes around the name > whenever you use it, as in x$'%y-%m-%d' > > - Phil Spector > Statistical Computing Facility > Department of Statistics > UC Berkeley > spector at stat.berkeley.edu > > On Tue, 14 Feb 2006, Diethelm Wuertz wrote: > >> >> >> I have a file named "test.csv" with the following 3 lines: >> >> %y-%m-%d;VALUE >> 1999-01-01;100 >> 2000-12-31;999 >> >> >> > read.table("test.csv", header = TRUE, sep = ";") >> >> delivers: >> >> X.y..m..d VALUE >> 1 1999-01-01 100 >> 2 2000-12-31 999 >> >> >> I would like to see the following ... >> >> %y-%m-%d VALUE >> 1 1999-01-01 100 >> 2 2000-12-31 999 >> >> >> Note, >> >> > readLines("test.csv", 1) >> >> delivers >> >> [1] "%y-%m-%d;VALUE" >> >> >> Is this possible ??? >> >> >> Thanks DW >> >> ______________________________________________ >> R-help at stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! >> http://www.R-project.org/posting-guide.html >> >
On Tue, 14 Feb 2006, Diethelm Wuertz wrote:> Thanks a lot that works fine! > > Next problem, if I would have my own package, and the file "test.csv" > would be located in the data directory > > How to use the function data to get > > > data(test) > > resulting in: > > > test > > %y-%m-%d VALUE > 1 1999-01-01 100 > 2 2000-12-31 999 > >I think you might be stuck in a particular mindset about this. Does the .csv file have to be called test.csv? If not then if it is called data.csv say, you can have in your data directory a file test.R with the code: read.table("data.csv", header = TRUE, sep = ";", check.names = FALSE) Alternatively you can have the data in the file test.R, plus the code to read it in as desired. Creating a data structure and reading it back in with dput and dget is one way to do this. See page 11 of the Writing R Extensions manual for the possible formats of files in the data directory: "The data subdirectory is for additional data files the package makes available for loading using data(). Currently, data files can have one of three types as indicated by their extension: plain R code (.R or .r), tables (.tab, .txt, or .csv), or save() images (.RData or .rda). (All ports of R use the same binary (XDR) format and can read compressed images. Use images saved with save(, compress = TRUE) to save space.) Note that R code should be self-sufficient and not make use of extra functionality provided by the package, so that the data file can also be used without having to load the package." David Scott _________________________________________________________________ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: d.scott at auckland.ac.nz Graduate Officer, Department of Statistics
Hi it appears to me that read.table is very slow for reading large data files (mine are 200,000 rows). Is there a better way? Thanks! Max -- Maximilian O. Kauer, Ph.D. Department of Genetics, White lab 333 Cedar St, NSB 386 PO Box 208005 New Haven, CT 06510
Hi, I have some column vector in txt or xls and I need to load into R as numeric vector. I use the read.table (X=read.table(123.txt”) command but the program say that “X is not a numeric vector” Where is the problem? Matías University of Oviedo, Spain [[alternative HTML version deleted]]
Matias Mayor Fernandez wrote:> Hi, > > > > I have some column vector in txt or xls and I need to load into R as numeric > vector. > > > > I use the read.table (X=read.table(123.txt?) command but the program say > that ?X is not a numeric vector?No, I think you got: Error: syntax error in "(X=read.table(123.txt" or you have used another call without the syntax error in it. In any case, please be more specific what you did. You might also want to copy the first few lines of file 123.txt in your mail. Uwe Ligges> > > > > Where is the problem? > > > > Mat?as > > > > University of Oviedo, > > > > Spain > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
From: Uwe Ligges> > Matias Mayor Fernandez wrote: > > > Hi, > > > > > > > > I have some column vector in txt or xls and I need to load > into R as > > numeric vector. > > > > > > > > I use the read.table (X=read.table(123.txt") command but > the program > > say that "X is not a numeric vector" > > No, I think you got: > > Error: syntax error in "(X=read.table(123.txt" > > or you have used another call without the syntax error in it. > > In any case, please be more specific what you did. You might > also want > to copy the first few lines of file 123.txt in your mail.Besides, if Matias only has one column of data and want that read in as a vector, scan() is really more appropriate. Andy> Uwe Ligges > > > > > > > > > > > > Where is the problem? > > > > > > > > Mat?as > > > > > > > > University of Oviedo, > > > > > > > > Spain > > > > > > [[alternative HTML version deleted]] > > > > > > > > > ---------------------------------------------------------------------- > > -- > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
On 3/8/06 8:31 AM, "Liaw, Andy" <andy_liaw at merck.com> wrote:> From: Uwe Ligges >> >> Matias Mayor Fernandez wrote: >> >>> Hi, >>> >>> >>> >>> I have some column vector in txt or xls and I need to load >> into R as >>> numeric vector. >>> >>> >>> >>> I use the read.table (X=read.table(123.txt") command but >> the program >>> say that "X is not a numeric vector"See here if you want to think of your data as a single-column table: http://cran.r-project.org/doc/manuals/R-data.html#Spreadsheet_002dlike-data Sean