forked from katiejolly/met-council-R
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10-reading-in-data2.Rmd
28 lines (15 loc) · 1.09 KB
/
10-reading-in-data2.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Reading in data, revisited
R can read data from text files (this includes csv, tsv, txt, etc.) as well as from other statistical software like Excel, SAS, Stata etc.
## Rectangular data
For reading in rectangular text data, `readr` is your best bet. For a csv, your code would look like:
```{r eval = FALSE}
data <- read_csv(...)
```
## Data from other statistical software
The `haven` package is best for reading in data from SAS, Stata, and SPSS. The `readxl` package works for all excel files, including options for sheets and things like that.
## GIS data
Packages like `sf` and `raster` work for importing/writing vector and raster data, respectively.
## Writing data
As well as reading in a variety of different data formats, R can also write to these formats.
## Cleaning data
Along with wrangling, there are a few packages that help with the data reading process. [janitor](https://github.com/sfirke/janitor) is one of my favorites. I like the `clean_names()` function a lot because it will automatically make your column names easily machine readable (no spaces, special characters, etc).