Hi, Could you please help me? I am trying to load an csv-file in R, but it works wrong! My data is 0,0127 -0,0016 0,0113 0,0037 -0,0025> Ret<-read.csv("Ret.csv") > RetX0 X0127 1 0 16 2 0 113 3 0 37 4 0 25 Thank you in advance! -- Best regards, Andy [[alternative HTML version deleted]]
Use scan: scan("Ret.csv", dec = ",") On Thu, Jul 2, 2009 at 7:47 AM, Andriy Fetsun <fetsun@googlemail.com> wrote:> Hi, > > Could you please help me? > > I am trying to load an csv-file in R, but it works wrong! > > My data is > > > 0,0127 > > -0,0016 > > 0,0113 > > 0,0037 > > -0,0025 > > > > Ret<-read.csv("Ret.csv") > > Ret > X0 X0127 > 1 0 16 > 2 0 113 > 3 0 37 > 4 0 25 > > Thank you in advance! > > -- > Best regards, > > Andy > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
On Jul 2, 2009, at 6:47 AM, Andriy Fetsun wrote:> Hi, > > Could you please help me? > > I am trying to load an csv-file in R, but it works wrong! > > My data is > > > 0,0127 > > -0,0016 > > 0,0113 > > 0,0037 > > -0,0025 > > >> Ret<-read.csv("Ret.csv") >> Ret > X0 X0127 > 1 0 16 > 2 0 113 > 3 0 37 > 4 0 25 >?read.csv read.csv(file, header = TRUE, sep = ",", quote="\"", dec=".", fill = TRUE, comment.char="", ...) So the default behavior is for the first line to be interpreted as column names. In the future please use an informative Subject line (as the Posting Guide suggests.) David Winsemius, MD Heritage Laboratories West Hartford, CT
Hi,> I am trying to load an csv-file in R, but it works wrong! > > My data is > > > 0,0127 > > -0,0016 > > 0,0113 > > 0,0037 > > -0,0025 > > >> Ret<-read.csv("Ret.csv") >> Ret > X0 X0127 > 1 0 16 > 2 0 113 > 3 0 37 > 4 0 25This looks correct to me. The read.csv function assumes the first line in the file is a header, and it also uses the "," character a the separator between columns. Try: ret <- read.csvl('Ret.csv', header=FALSE) Still you'll have two columns, but I'm guessing the "," in your data is the decimal separator, in which case you should use read.csv2 (its "dec" argument defaults to ","). alternatively, since your file just looks like one column, you can use the readLine() function and it will get you what you want, too. -steve -- Steve Lianoglou Graduate Student: Physiology, Biophysics and Systems Biology Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
Andriy Fetsun wrote:> Hi, > > Could you please help me? > > I am trying to load an csv-file in R, but it works wrong!See ?read.csv and about decimal different characters. Uwe Ligges> My data is > > > 0,0127 > > -0,0016 > > 0,0113 > > 0,0037 > > -0,0025 > > >> Ret<-read.csv("Ret.csv") >> Ret > X0 X0127 > 1 0 16 > 2 0 113 > 3 0 37 > 4 0 25 > > Thank you in advance! >
Andriy, It does exactly what you want it to do. So if the result is not what you expected, then you are supplying R with a wrong command. If you would have read the helpfile of read.csv you would have noticed the sep and dec argument would be very useful in this case. Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -----Oorspronkelijk bericht----- Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens Andriy Fetsun Verzonden: donderdag 2 juli 2009 12:48 Aan: r-help at r-project.org Onderwerp: [R] (no subject) Hi, Could you please help me? I am trying to load an csv-file in R, but it works wrong! My data is 0,0127 -0,0016 0,0113 0,0037 -0,0025> Ret<-read.csv("Ret.csv") > RetX0 X0127 1 0 16 2 0 113 3 0 37 4 0 25 Thank you in advance! -- Best regards, Andy [[alternative HTML version deleted]] ______________________________________________ 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. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.