0

I often come across larger datasets where I don't know what they actually contain.

Instead of waiting for them to be opened in a conventional text editor or within the RStudio text editor, for example, I would like to look at the first few lines.

I don't even have to parse the contents, scanning these first few lines will help me to determine what method to use.

Is there a function/package for this?

grssnbchr
  • 2,877
  • 7
  • 37
  • 71
  • There is an answer to your question here I believe: http://stackoverflow.com/questions/21222113/how-to-read-first-1000-lines-of-csv-file-into-r – jimh Mar 04 '15 at 20:47

2 Answers2

2

read.table has an nrows option:

nrows: integer: the maximum number of rows to read in.  Negative and
      other invalid values are ignored.

so read in a few and see what you've got.

If you have a Unix environment then the command head file.csv will show the first ten lines. There are lots of other useful Unix commands (guess what tail file.csv does) and even if you are on Windows you could benefit from installing Cygwin and learning it!

Spacedman
  • 92,590
  • 12
  • 140
  • 224
0

Here is an answer to your question:

How to read first 1000 lines of .csv file into R?

Basically use nrows in read.csv or read.table...

Community
  • 1
  • 1
jimh
  • 1,651
  • 2
  • 15
  • 28