BIOL548O / Discussion

A repository for course discussion in BIOL548O
0 stars 0 forks source link

Read the functions that read your data #18

Open aammd opened 8 years ago

aammd commented 8 years ago

Hello @BIOL548O/all ,

start your week with some free R advice! :computer: :money_with_wings:

Everyone is doing a great job so far with their data cleaning scripts! I've noticed that often, after reading in data, lots of time is being spent "fixing" the resulting table:

A lot of these issues can be fixed most easily by mastering the function that reads in the data. There are three good ways to read in data that will cover most common cases in this class. Save yourself lots of time and read their help files!

For example:

column types

Let's say you have one character column (an id variable) and one numeric column (e.g. mass):

readr::read_csv("data-raw/mydata.csv", col_types = cols(first_col = col_character(),
                                                        secnd_col = col_double()))

or, equivalently

readr::read_csv("data-raw/mydata.csv", col_types = "cd")

specify your "missing" code:

All three functions also let you specify what your code for "missing" is. Let's say that in your data the missing value is coded "N/A":

read.delim("data-raw/mydata.csv", na.strings = "N/A")

readxl::read_excel("data-raw/mydata.csv", na = "N/A")

readr::read_csv("data-raw/mydata.csv", na = "N/A")