Dear All, I've been using R for windows for a while, without too many problems. However, I'm forced to use the MAC OS system for teaching, because our teaching labs are mac only (not my idea!!). I have a very basic problem, but one that doesn't appear on the FAQs. I simply want to import data from a spreadsheet. I'm using exactly what works fine on Windows, namely: 1 save the file from Excel as tab-delimited, say called "test.txt", with the variable names in the first row. 2 Read in into R with test<-read.table("test.txt", header=T) It does weird things, especially if any variables are characters. For example, it has omitted the 5th observation for the 1st variable, and then appended it to the first variable name. I've tried read.csv with csv files, read.delim, etc. None seem to work. Am I being really silly, and if so, how do you do it? Or is there an easier way to get data into the mac port? Or is the mac port entirely useless? Can anyone out there help? Thanks Hamish McCallum -- Dr Hamish McCallum Department of Zoology and Entomology The University of Queensland Brisbane 4072 Australia Phone (+617) 3365 2450 Fax (+617) 3365 1655
Hamish, I usually save Excel files as CSV, and then use read.csv() to get them into R. Also, there are variants of read.table() that seem more successful at reading in delimited files (see read.delim, read.delim2). Regards, Andrew C. Ward CAPE Centre Department of Chemical Engineering The University of Queensland Brisbane Qld 4072 Australia andreww at cheque.uq.edu.au Quoting Hamish McCallum <hmccallum at zen.uq.edu.au>:> Dear All, > > I've been using R for windows for a while, without too many problems. > However, I'm forced to use the MAC OS system for teaching, because our > teaching labs are mac only (not my idea!!). I have a very basic problem, > but one that doesn't appear on the FAQs. I simply want to import data > from a spreadsheet. I'm using exactly what works fine on Windows, namely: > > 1 save the file from Excel as tab-delimited, say called "test.txt", > with the variable names in the first row. > 2 Read in into R with > test<-read.table("test.txt", header=T) > > It does weird things, especially if any variables are characters. For > example, it has omitted the 5th observation for the 1st variable, and > then appended it to the first variable name. I've tried read.csv with > csv files, read.delim, etc. None seem to work. Am I being really silly, > and if so, how do you do it? Or is there an easier way to get data into > the mac port? Or is the mac port entirely useless? > > Can anyone out there help? > > Thanks > > Hamish McCallum > > -- > Dr Hamish McCallum > Department of Zoology and Entomology > The University of Queensland > Brisbane 4072 > Australia > Phone (+617) 3365 2450 Fax (+617) 3365 1655 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >
It should be the same, but then I know nothing about R or Excel for Mac. Obvious things to check is if it is Excel or R that is the problem, i.e. have you tested to save your Excel data on a Mac and then tried to import it into R on a Windows machine and vice versa? When Europe wakes up they might be able to help you out if you tell them what version you are running. What does R.Version() say? Henrik Bengtsson> -----Original Message----- > From: r-help-admin at stat.math.ethz.ch > [mailto:r-help-admin at stat.math.ethz.ch] On Behalf Of Hamish McCallum > Sent: den 22 januari 2003 16:10 > To: R-help at lists.R-project.org > Subject: [R] Read.table for macs > > > Dear All, > > I've been using R for windows for a while, without too many problems. > However, I'm forced to use the MAC OS system for teaching, > because our > teaching labs are mac only (not my idea!!). I have a very > basic problem, > but one that doesn't appear on the FAQs. I simply want to import data > from a spreadsheet. I'm using exactly what works fine on > Windows, namely: > > 1 save the file from Excel as tab-delimited, say called > "test.txt", > with the variable names in the first row. > 2 Read in into R with > test<-read.table("test.txt", header=T) > > It does weird things, especially if any variables are characters. For > example, it has omitted the 5th observation for the 1st variable, and > then appended it to the first variable name. I've tried read.csv with > csv files, read.delim, etc. None seem to work. Am I being > really silly, > and if so, how do you do it? Or is there an easier way to get > data into > the mac port? Or is the mac port entirely useless? > > Can anyone out there help? > > Thanks > > Hamish McCallum > > -- > Dr Hamish McCallum > Department of Zoology and Entomology > The University of Queensland > Brisbane 4072 > Australia > Phone (+617) 3365 2450 Fax (+617) 3365 1655 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/> r-help > >
I detect an anti Mac theme, I do not wish to attribute blame but suggest that Excel does funny things when it dumps tab separated text files, like adding unprintable characters and trailing spaces. My approach is to use BBedit (which is free) to: 1) zap gremlins 2) globally substitute \ \t for \t (ie remove trailing spaces which R does not ignore). 3) convert DOS new lines to Mac new lines. Equally you could use awk etc. on a Mac to do this. In general it is not safe to do this cleaning operation on a DOS/Windows system as conversions may still take place on transmission to an Apple. On Wednesday, January 22, 2003, at 05:10 am, Hamish McCallum wrote:> Dear All, > > I've been using R for windows for a while, without too many problems. > However, I'm forced to use the MAC OS system for teaching, because our > teaching labs are mac only (not my idea!!). I have a very basic > problem, but one that doesn't appear on the FAQs. I simply want to > import data from a spreadsheet. I'm using exactly what works fine on > Windows, namely: > > 1 save the file from Excel as tab-delimited, say called "test.txt", > with the variable names in the first row. > 2 Read in into R with > test<-read.table("test.txt", header=T) > > It does weird things, especially if any variables are characters. For > example, it has omitted the 5th observation for the 1st variable, and > then appended it to the first variable name. I've tried read.csv with > csv files, read.delim, etc. None seem to work. Am I being really > silly, and if so, how do you do it? Or is there an easier way to get > data into the mac port? Or is the mac port entirely useless? > > Can anyone out there help? > > Thanks > > Hamish McCallum > > -- > Dr Hamish McCallum > Department of Zoology and Entomology > The University of Queensland > Brisbane 4072 > Australia > Phone (+617) 3365 2450 Fax (+617) 3365 1655 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help > >Dr. P. B. Pynsent, Research and Teaching Centre, Royal Orthopaedic Hospital, Birmingham, B31 2AP, U.K.
Hamish, I suspect your problem might be with Excel. try copying the data (and just your data) to a clean spreadsheet and then save to a tab-delimited text file. Removes all sorts of unwanted invisible garbage. Then import into R with: test<-read.table("test.txt", header=T, sep="\t") Mikkel Hamish Callum wrote: Dear All, I've been using R for windows for a while, without too many problems. However, I'm forced to use the MAC OS system for teaching, because our teaching labs are mac only (not my idea!!). I have a very basic problem, but one that doesn't appear on the FAQs. I simply want to import data from a spreadsheet. I'm using exactly what works fine on Windows, namely: 1 save the file from Excel as tab-delimited, say called "test.txt", with the variable names in the first row. 2 Read in into R with Dear All, I've been using R for windows for a while, without too many problems. However, I'm forced to use the MAC OS system for teaching, because our teaching labs are mac only (not my idea!!). I have a very basic problem, but one that doesn't appear on the FAQs. I simply want to import data from a spreadsheet. I'm using exactly what works fine on Windows, namely: 1 save the file from Excel as tab-delimited, say called "test.txt", with the variable names in the first row. 2 Read in into R with test<-read.table("test.txt", header=T) It does weird things, especially if any variables are characters. For example, it has omitted the 5th observation for the 1st variable, and then appended it to the first variable name. I've tried read.csv with csv files, read.delim, etc. None seem to work. Am I being really silly, and if so, how do you do it? Or is there an easier way to get data into the mac port? Or is the mac port entirely useless? Can anyone out there help? Thanks It does weird things, especially if any variables are characters. For example, it has omitted the 5th observation for the 1st variable, and then appended it to the first variable name. I've tried read.csv with csv files, read.delim, etc. None seem to work. Am I being really silly, and if so, how do you do it? Or is there an easier way to get data into the mac port? Or is the mac port entirely useless? Can anyone out there help? Thanks