1. Importing .xlsx, .csv., and .txt datasets and creating a “tibble” for each.
library(readxl)
read_excel("Practice 3 Spreadsheet.xlsx", col_names = F)
## # A tibble: 15 x 7
## X__1 X__2 X__3 X__4 X__5 X__6 X__7
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 size 3 12 13 81 13 55
## 2 gold 4 55 56 3 56 9
## 3 city 3 63 64 6 64 22
## 4 state 5 89 90 8 90 72
## 5 address 7 34 35 2 35 68
## 6 phone 8 12 13 6 13 20
## 7 married 9 18 19 3 19 35
## 8 single 7 97 98 8 98 88
## 9 good 5 48 49 2 49 96
## 10 poor 4 39 40 5 40 75
## 11 open 2 34 35 8 35 62
## 12 water 1 87 88 21 88 55
## 13 fire 6 55 56 87 56 25
## 14 help 3 24 25 5 25 45
## 15 large 8 11 12 4 12 20
library(dplyr)
csv_dataset <- read.csv("Practice 3 Spreadsheet.csv", header = FALSE)
csv_dataset <- tbl_df(csv_dataset)
csv_dataset
## # A tibble: 15 x 7
## V1 V2 V3 V4 V5 V6 V7
## <fctr> <int> <int> <int> <int> <int> <int>
## 1 size 3 12 13 81 13 55
## 2 gold 4 55 56 3 56 9
## 3 city 3 63 64 6 64 22
## 4 state 5 89 90 8 90 72
## 5 address 7 34 35 2 35 68
## 6 phone 8 12 13 6 13 20
## 7 married 9 18 19 3 19 35
## 8 single 7 97 98 8 98 88
## 9 good 5 48 49 2 49 96
## 10 poor 4 39 40 5 40 75
## 11 open 2 34 35 8 35 62
## 12 water 1 87 88 21 88 55
## 13 fire 6 55 56 87 56 25
## 14 help 3 24 25 5 25 45
## 15 large 8 11 12 4 12 20
text_dataset <- read.table("Practice 3 Spreadsheet.txt", header = FALSE)
text_dataset <- tbl_df(text_dataset)
text_dataset
## # A tibble: 15 x 7
## V1 V2 V3 V4 V5 V6 V7
## <fctr> <int> <int> <int> <int> <int> <int>
## 1 size 3 12 13 81 13 55
## 2 gold 4 55 56 3 56 9
## 3 city 3 63 64 6 64 22
## 4 state 5 89 90 8 90 72
## 5 address 7 34 35 2 35 68
## 6 phone 8 12 13 6 13 20
## 7 married 9 18 19 3 19 35
## 8 single 7 97 98 8 98 88
## 9 good 5 48 49 2 49 96
## 10 poor 4 39 40 5 40 75
## 11 open 2 34 35 8 35 62
## 12 water 1 87 88 21 88 55
## 13 fire 6 55 56 87 56 25
## 14 help 3 24 25 5 25 45
## 15 large 8 11 12 4 12 20
2. Import .csv file from the web and create a “tibble”.
height_weight_dataset <- read.csv(url("http://www.personal.psu.edu/dlp/alphaheight_weight_dataset.csv"))
height_weight_dataset <- tbl_df(height_weight_dataset)
height_weight_dataset
## # A tibble: 200 x 4
## Index Height Weight Gender
## <int> <dbl> <dbl> <fctr>
## 1 1 65.78 112.99 female
## 2 2 71.52 136.49 male
## 3 3 69.40 153.03 male
## 4 4 68.22 142.34 female
## 5 5 67.79 144.30 male
## 6 6 68.70 123.30 male
## 7 7 69.80 141.49 male
## 8 8 70.01 136.46 female
## 9 9 67.90 112.37 male
## 10 10 66.78 120.67 male
## # ... with 190 more rows
3. Import .csv file from the web and create a “tibble”.
titanic_dataset <- read.csv(url("http://www.personal.psu.edu/dlp/w540/datasets/titanicsurvival.csv"))
titanic_dataset <- tbl_df(titanic_dataset)
titanic_dataset
## # A tibble: 2,201 x 4
## Class Age Sex Survive
## <int> <int> <int> <int>
## 1 1 1 1 1
## 2 1 1 1 1
## 3 1 1 1 1
## 4 1 1 1 1
## 5 1 1 1 1
## 6 1 1 1 1
## 7 1 1 1 1
## 8 1 1 1 1
## 9 1 1 1 1
## 10 1 1 1 1
## # ... with 2,191 more rows
4. Import SPSS .sav file from the web and create a “tibble”.
library(haven)
read_sav("https://cehd.gmu.edu/assets/dimitrovbook/EXAMPLE_23_1.sav")
## # A tibble: 1,028 x 12
## Illness Item_1 Item_2 Item_3 Item_4 Item_5 Item_6
## <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl+lbl> <dbl> <dbl+lbl> <dbl+lbl>
## 1 1 4 3 3 3 4 2
## 2 0 3 2 4 3 4 3
## 3 0 4 3 4 3 3 2
## 4 1 5 5 4 5 4 5
## 5 1 2 2 2 2 2 2
## 6 0 3 2 2 3 2 1
## 7 0 2 1 1 2 1 2
## 8 0 3 2 4 4 2 2
## 9 0 2 4 3 3 3 3
## 10 1 1 1 1 1 1 1
## # ... with 1,018 more rows, and 5 more variables: Item_7 <dbl>,
## # Item_8 <dbl+lbl>, Item_9 <dbl+lbl>, Item_10 <dbl+lbl>, Item_11 <dbl>