Created
September 23, 2017 15:06
-
-
Save aravindhebbali/ade2338fd725438f57345e6bd0bccfac to your computer and use it in GitHub Desktop.
A Complete Guide to Importing Data into R - Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install | |
install.packages('readr') | |
install.packages('haven') | |
# library | |
library(readr) | |
library(haven) | |
# read_csv | |
read_csv('hsb2.csv') | |
# col_names | |
read_csv('hsb2.csv', col_names = FALSE) | |
# skip records | |
read_csv('hsb2.csv', col_names = FALSE, skip = 1) | |
# max records to read | |
read_csv('hsb2.csv', n_max = 50) | |
# read space separated values | |
read_table2('hsb1.csv') | |
# check column type | |
spec_csv('hsb2.csv') | |
# specify column type | |
read_csv('hsb2.csv', col_types = list(col_integer(), col_factor(levels = c(0, 1)), | |
col_factor(levels = c(1, 2, 3, 4)), col_factor(levels = c(1, 2, 3)), | |
col_factor(levels = c(1, 2)), col_factor(levels = c(1, 2, 3)), | |
col_integer(), col_integer(), col_integer(), col_integer(), col_integer()) | |
) | |
# read specific columns | |
read_csv('hsb2.csv', col_types = cols_only(id = col_integer(), | |
prog = col_factor(levels = c(1, 2, 3)), read = col_integer()) | |
) | |
# stata | |
read_stata('airline.dta') | |
# spss | |
read_spss('employee.sav') | |
# sas | |
read_sas('airline.sas7bdat') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment