-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.Rmd
101 lines (87 loc) · 2.06 KB
/
template.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: "Simple document"
output: github_document
---
I'm an R Markdown document!
```{r, echo = FALSE, message = FALSE}
library(tidyverse)
library(readxl)
library(haven)
```
## Import some data
I want to import "FAS_litters.csv"
```{r}
litters_df = read_csv("./data/FAS_litters.csv") # this is a relative path
# don't use absolute path, absolute makes it un-sharable
```
I imported the dataset. Now I need better names.
```{r}
names(litters_df)
litters_df = janitor::clean_names(litters_df) # could also import library janitor at the top, but janitor is large
```
Now I have better names. Let's take a look at the dataset.
```{r}
litters_df
head(litters_df, 20)
tail(litters_df, 5)
```
Now I use a lot is:
```{r, eval = FALSE}
view(litters_df)
```
Here is `skimr`:
```{r}
skimr::skim(litters_df)
```
## Arguments in "read_csv"
```{r}
# skip: skip the first 5 lines, don't display column names, set all "Low8" as na
litters_df =
read_csv(
"data/FAS_litters.csv",
skip = 5,
col_names = FALSE,
na = "Low8")
litters_df
```
# parsing column
```{r}
# col_types: read_csv will guess the type of the data, but you can change it manually
litters_data = read_csv(file = "./data/FAS_litters.csv",
col_types = cols(
Group = col_character(),
`Litter Number` = col_character(),
`GD0 weight` = col_double(),
`GD18 weight` = col_double(),
`GD of Birth` = col_integer(),
`Pups born alive` = col_integer(),
`Pups dead @ birth` = col_integer(),
`Pups survive` = col_integer()
)
)
tail(litters_data)
```
## Reading from Excel
```{r}
mlb11_df = read_excel("data/mlb11.xlsx")
mlb11_df
```
read LotR data
```{r}
fellow_df = read_excel("data/LotR_Words.xlsx", range = "B3:D6")
fellow_df
```
## read a SAS file
this cannot work rn
```{r, eval = FALSE}
pulse_df = read_sas("data/public_pulse_data.sas7bdat")
```
## why to never use "read.csv": does not give "tibble" and that's really bad
```{r}
litters_df_base = read.csv("data/FAS_litters.csv")
litters_df_base
```
## how do i export data
```{r}
write_csv(fellow_df, "data/fellowship_words.csv")
```