Final Thoughts
1. Final Thoughts
There's something I haven't told you yet. When I said that read-dot-table was utils' main importing functions, I was serious.2. Wrappers
Actually, read-dot-csv and read-dot-delim, the functions to import comma-separated values and tab-delimited files, are so-called wrapper functions around read-dot-table. They call read-dot-table behind the scenes, but with different default arguments to match the specific formats.3. read.csv
For read-dot-csv, the default for header is TRUE and for sep is a comma, so you don't have to manually specify these anymore. This means that this read-dot-table call to import the CSV version of states, is exactly the same as this read-dot-csv call. Shorter and easier to read, if you ask me.4. read.delim
Likewise, read-dot-delim sets the header and sep argument, among some others. This call to import the tab-delimited version of states, is exactly the same as this read-dot-delim call.5. Documentation
If you have a look at the documentation of read-dot-table, you'll see that there are two more functions in there that we haven't discussed yet. read-dot-csv2 and read-dot-delim2. These functions exist to deal with regional differences in representing numbers.6. Locale differences
Have a look at this csv file, states_aye-dot-csv, typical for the US and Great Britain, and its counterpart, states_nay-dot-csv. You'll notice that the states_nay uses commas for decimal points, as opposed to the dot for states_aye-dot-csv. This means that they can't use the comma as the field-delimiter anymore, they need a semicolon.7. Locale differences
That's why the read-dot-csv2 and read-dot-delim2 functions exist. Can you spot the difference in default arguments again?8. states_nay.csv
Let's try to import the states_nay-dot-csv file with the basic read-dot-csv function. R gives a result, but it clearly is not the result we want. It's a dataset with 5 observations but a single variable. If we try again with read-dot-csv2, it works perfectly this time! These were just some side notes to wrap up on this chapter. By now, you now how to import comma-separated, tab-delimited and even more exotic data formats. But there's much more to learn!9. Let's practice!
I hope to see you in the next chapter to learn about the powerful readr and data table packages!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.