0

How can I tell R to ignore the leading separators when reading from a CSV file with space separators?

For instance, if I have the file data.txt with the following contents (notice the leading spaces)

   1 2 3
   4 5 6

and then I run

> read.csv ("data.txt", header = FALSE, sep = " ")
  V1 V2 V3 V4 V5 V6
1 NA NA NA  1  2  3
2 NA NA NA  4  5  6

I get columns V1, V2, V3 that represent the leading spaces and since no values are there, they're full of NAs.

Can I get a data frame with 3 columns and 2 rows from this input directly from read.csv? (or maybe from read.table?)

Harald
  • 3,110
  • 1
  • 24
  • 35

0 Answers0