Tips of Reading CSV Data

Many times CSV data is not in good format. It may contains some garbage that we don’t want to import into our table.

So here are some tips of reading CSV file:

  1. Read the CSV file in text editor to have idea of how the data looks like
  2. Skip Blank lines
  3. Specify whether it includes header or not
  4. Define variable type on each column to make sure it gets correct one

Example:

GDP <- read.csv(“GDP.csv”, header = FALSE, na.strings = “”, skip = 5,
blank.lines.skip = TRUE, nrows = 190,
colClasses = c(“character”, “integer”, “NULL”, “character”,
“character”, rep(“NULL”, 5)))
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s