Hey, I am having problems with importing a csv file to R. I could read the file by typing: read.csv(file="/Users/kama/Desktop/skatter.csv", header=TRUE, sep=";") However, i can not analyze the "skatter" - for ex, when i type: skatter = read.csv("skatter.csv") i get this message: Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : What i need is to import this file and analyze it using for example histogram. I have Mac(update) and the file is saved in csv file... and I'm quite new user of R. Thank you very much! -- View this message in context: http://r.789695.n4.nabble.com/HELP-me-please-with-import-of-csv-to-R-tp4636019.html Sent from the R help mailing list archive at Nabble.com.
Hi, On Tue, Jul 10, 2012 at 12:48 PM, F86 <faradj.g at gmail.com> wrote:> Hey, > > I am having problems with importing a csv file to R. > > I could read the file by typing: > read.csv(file="/Users/kama/Desktop/skatter.csv", header=TRUE, sep=";")So that command does work?> However, i can not analyze the "skatter" - for ex, when i type: skatter > = read.csv("skatter.csv")Then you need the above command, not what you type here: skatter <- read.csv(file="/Users/kama/Desktop/skatter.csv", header=TRUE, sep=";") But note that if sep=";" then you don't have a csv file and should properly use read.table() instead.> i get this message: > > Error in file(file, "rt") : cannot open the connection > In addition: Warning message: > In file(file, "rt") : > > What i need is to import this file and analyze it using for example > histogram. > > I have Mac(update) and the file is saved in csv file... and I'm quite new > user of R.That error means that R can't find the file where you told it to look. Specifying the full and complete path as in your first example should work. If you're having problems with paths (which are a Mac issue and not at all an R issue), you could also try read.table(file.choose(), header=TRUE, sep=";") I think that file.choose() should work on Mac. The Intro to R document that came with R might also be of use. Sarah -- Sarah Goslee http://www.functionaldiversity.org
Try putting the data into some kind of object. I'm not sure what R does with the data from read.csv. I always 1) read the data into an object 2) print the data out 3) attach the data so that the headers become objects that contain the data 4) and yes, print the data out using ls 5) check the output file just in case one of 1-4 throw an error. v_data <- read.table("C:\\Users\\Frank\\Options\\CBOE\\VZ\\2012\\VZ_2012_03_Summary_V0_R.TXT",header=T) v_data attach(v_data) ls(v_data) GL Frank Chicago, IL> Date: Tue, 10 Jul 2012 09:48:04 -0700 > From: faradj.g@gmail.com > To: r-help@r-project.org > Subject: [R] HELP me please with import of csv to R > > Hey, > > I am having problems with importing a csv file to R. > > I could read the file by typing: > read.csv(file="/Users/kama/Desktop/skatter.csv", header=TRUE, sep=";") > > However, i can not analyze the "skatter" - for ex, when i type: skatter > = read.csv("skatter.csv") > > i get this message: > > Error in file(file, "rt") : cannot open the connection > In addition: Warning message: > In file(file, "rt") : > > What i need is to import this file and analyze it using for example > histogram. > > I have Mac(update) and the file is saved in csv file... and I'm quite new > user of R. > > > > Thank you very much! > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/HELP-me-please-with-import-of-csv-to-R-tp4636019.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.[[alternative HTML version deleted]]
On Tue, Jul 10, 2012 at 4:23 PM, FJ M <chicagobrownblue at hotmail.com> wrote:> 3) attach the data so that the headers become objects that contain the data > attach(v_data)This is a discouraged practice as it leads to difficult to trace errors and non-local effects. Some "big names" of the R universe suggest it [I think V of V&R mentioned it in Nashville] but others are just as strongly against, particularly for beginners. Beter is to make use of formula= and data= arguments when available, and with/within elsewise. Best, Michael