Re: [R] How to Import Data

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed 22 Feb 2006 - 01:32:57 EST

On 2/21/2006 9:13 AM, Adaikalavan Ramasamy wrote:

> 1) You need to use sep="," which is appropriate for a CSV file.
> 
> 2) You need to specify the FULL path to the file. See 
> http://cran.r-project.org/bin/windows/base/rw-FAQ.html#R-can_0027t-find-my-file

The advice to look at the FAQ is good, but it's not true that you need the full path. Like other programs, R maintains a current working directory, and paths can be specified relative to that. I usually put a line like

setwd('c:/my/working/dir')

at the start of scripts, so that the current directory is changed from the beginning. Then I can use simple filenames to read files.

The other advice I usually give is to specify "file.choose()" instead of an explicit filename; this will open a file selection dialog. (In my opinion, this should be the default, but some people disagree quite strongly.)

Duncan Murdoch

> 
> 3) You can use read.csv which is the read.table variant for CSV files.
> 
> 
> For example
> 
>   a <- read.csv( file="c:/Progra~1/Docume~1/ramasamy/x111.csv" )
> 
> might work if you replace it with your full path. If you have the
> _unique_ rownames in the first column, you can add the argument
> "row.names=1" in the call.
> 
> Regards, Adai
> 
> 
> 
> On Tue, 2006-02-21 at 08:52 -0500, Carl Klarner wrote:

>> Hello,
>> I am a very new user of R. I've spent several hours trying to import
>> data, so I feel okay asking the list for help. I had an Excel file,
>> then I turned it into a "csv" file, as instructed by directions. My
>> filename is "x111.csv." I then used the following commands to read this
>> (fairly small) dataset in.
>>
>> x111 <-read.table(file='x111.csv',
>> sep="",header=T,
>> quote="",comment.char="",as.is=T)
>>
>> I then get the following error message.
>>
>> Error in file(file, "r") : unable to open connection
>> In addition: Warning message:
>> cannot open file 'x111.csv', reason 'No such file or directory'
>>
>> I would imagine I'm not putting my csv file in the right location for R
>> to be able to read it. If that's the case, where should I put it? Or
>> is there something else I need to do to it first?
>> Thanks for your help,
>> Carl
>>
>> ______________________________________________
>> 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
>>
> 
> ______________________________________________
> 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

______________________________________________
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 Received on Wed Feb 22 02:49:18 2006

This archive was generated by hypermail 2.1.8 : Wed 22 Feb 2006 - 09:27:43 EST