0

I have csv files in which a couple of the fields in the first column have a leading whitespace. read.csv considers the whole line blank, even though there are data in the line. I can use blank.lines.skip = FALSE, but it just reads it in as a blank line.

I'd like to read in the data on those lines, so how do I get read.csv (or read.table or something) to ignore that whitespace?

The data look like this:

Sample Name Air BaseMixture

Offset  -0.0338367  -0.0338367

Slope   0.0200808   0.0200808

LiveTime    180.236 180.252

RealTime    255.934 280.701

LTMultiplier    1   1

.
.
.

Offset and Slope seem to have some sort of whitespace that makes read.csv give me this:

    Sample.Name Air BaseMixture

1   NA  NA  NA
2   NA  NA  NA
3   LiveTime    180.236 180.252
4   RealTime    255.934 280.701 
5   LTMultiplier    1   1

Your help is much appreciated. Thanks.

Henrik
  • 65,555
  • 14
  • 143
  • 159
  • 3
    What command do you use to read your file ? The default for read.table is sep"", which is one or more white space. So read.table(file="yourfile.csv") should work. – Chargaff Oct 25 '13 at 20:13
  • 1
    Please consider reading http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Asking your question(s) in a good way will makes everybody's life easier and will ensure you to get a quick and informative answer. – Chargaff Oct 25 '13 at 20:18
  • 2
    Please consider clarifying your use of the term csv. A csv will have actual _commas_ in the file. Your example does not, so it makes absolutely no sense to use `read.csv` rather than `read.table`. – joran Oct 25 '13 at 20:40

1 Answers1

0

You can use:

read.csv('filename.csv', strip.white=TRUE)