On Sep 21, 2009, at 12:19 PM, Cynthia Sadler wrote:

Hi,

I'm trying to read data from a collection of CSV files for processing and graphing. All of my files begin with "modrate" and end with ".csv". I think I have the regex working but I am stumped at trying to get read.table to work within an if statement.

This works:

> filepattern="modrate*"
> files <- list.files(pattern=filepattern)
> data <- read.table(files[1], header=TRUE, sep=",")

But I cannot get this to work:

> for (i in seq(along=files)) {
+ data <- read.table(files[i], header=TRUE, sep=",")
+ }
Error in make.names(col.names, unique = TRUE) :
 invalid multibyte string at '<ff><d8><ff><e0>'

The error message suggests that you might have strange characters in your header lines which make.names() is choking on. What is the result of substituting readLines with parameter of n=1 for the read.table() call on those files? Or perhaps you should be using "[[" rather than "[" to access the files list?



I'm sure I'm making a newbie mistake here.

Despite several years, I still consider myself a newbie.

I'm using R version 2.9.2 (2009-08-24) on Mac OS X, and didn't find anything about this in the help archives (though, as I'm new to this, I may not have searched in the best way). Any advice? Thanks.



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
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.

Reply via email to