-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImportingData.R
78 lines (51 loc) · 1.83 KB
/
ImportingData.R
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
# INSTALL AND LOAD PACKAGES ################################
library(datasets) # Load base packages manually
# Installs pacman ("package manager") if needed
if (!require("pacman")) install.packages("pacman")
# Use pacman to load add-on packages as desired
pacman::p_load(pacman, rio)
# ABOUT EXCEL FILES ########################################
# From the official R documentation
browseURL("http://j.mp/2aFZUrJ")
# You have been warned: ಠ_ಠ
# IMPORTING WITH RIO #######################################
# CSV
rio_csv <- import("~/Desktop/mbb.csv")
head(rio_csv)
# TXT
rio_txt <- import("~/Desktop/mbb.txt")
head(rio_txt)
# Excel XLSX
rio_xlsx <- import("~/Desktop/mbb.xlsx")
head(rio_xlsx)
# DATA VIEWER ##############################################
?View
View(rio_csv)
# READ.TABLE FOR TXT FILES #################################
# R's built-in function for text files (used by rio)
# TEXT FILES
# Load a spreadsheet that has been saved as tab-delimited
# text file. Need to give complete address to file. This
# command gives an error on missing data but works on
# complete data.
r_txt1 <- read.table("~/Desktop/mbb.txt", header = TRUE)
# This works with missing data by specifying the separator:
# \t is for tabs, sep = "," for commas. R converts missing
# to "NA"
r_txt2 <- read.table("~/Desktop/mbb.txt",
header = TRUE,
sep = "\t")
# READ.CSV FOR CSV FILES ###################################
# R's built-in function for csv files (also used by rio)
# CSV FILES
# Don't have to specify delimiters for missing data
# because CSV means "comma separated values"
trends.csv <- read.csv("~/Desktop/mbb.csv", header = TRUE)
# CLEAN UP #################################################
# Clear environment
rm(list = ls())
# Clear packages
p_unload(all) # Remove all add-ons
# Clear console
cat("\014") # ctrl+L
# Clear mind :)