Hi all, I have just started to use R for my PhD project and have no previous experience in programming. I am having trouble importing data to R. This is the output:> mydata <- read.table("Lv2.8.txt")Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'Lv2.8.txt': No such file or directory I know there is a file on my computer with this name though... What am I doing wrong? Thanks in advance! Tom -- View this message in context: http://r.789695.n4.nabble.com/Help-Importing-data-from-txt-and-xlsx-files-tp4554622p4554622.html Sent from the R help mailing list archive at Nabble.com.
Dear Tom, R does not searches your entire file system for the file. It only looks in the working directory. Have a look at ?setwd() and ?getwd() So you will need to set the working directory, use a relative path to the file or use and absolute path to the file. Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 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 AMFTom Verzonden: vrijdag 13 april 2012 14:29 Aan: r-help at r-project.org Onderwerp: [R] Help - Importing data from txt and xlsx files Hi all, I have just started to use R for my PhD project and have no previous experience in programming. I am having trouble importing data to R. This is the output:> mydata <- read.table("Lv2.8.txt")Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'Lv2.8.txt': No such file or directory I know there is a file on my computer with this name though... What am I doing wrong? Thanks in advance! Tom -- View this message in context: http://r.789695.n4.nabble.com/Help-Importing-data-from-txt-and-xlsx-files-tp4554622p4554622.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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * 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.
Dear Thierry, Thanks for your help. Now though, I try to import data from a txt file, and it says either> mydataframe <- read.table("Lv2.8.txt")Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 3 did not have 15 elements or> mydataframe <- read.table("Lv2.8.txt", header = TRUE)Error in read.table("Lv2.8.txt", header = TRUE) : more columns than column names even though I seem to have put a column name into the txt file for each column. Any ideas? Thanks again! Tom -- View this message in context: http://r.789695.n4.nabble.com/Help-Importing-data-from-txt-and-xlsx-files-tp4554622p4555001.html Sent from the R help mailing list archive at Nabble.com.
Hi all, it turns out I had left absent data as a blank space instead of filling it with a zero. Now I am able to import data. Thanks for all your help, I'm sure I will be calling on your expertise in future. Tom -- View this message in context: http://r.789695.n4.nabble.com/Help-Importing-data-from-txt-and-xlsx-files-tp4554622p4561522.html Sent from the R help mailing list archive at Nabble.com.