Section 11 Read Data
11.1 Function
Function | Explanation |
---|---|
setwd |
Set the working directory. Note the file path is given by / or \\ . |
getwd |
Get the current working directory. Note the file path is given by / or \\ . |
read.table |
Read a tabular data - it reads a file in table format and creates a data frame from it, with lines and variables to fields in the file. It is always convenient to assign the outputs from read.table to an R object. |
read.csv |
Read a csv file. It is always convenient to assign the outputs from read.csv to an R object. |
readLines |
Read lines of a text file |
source |
Read the R script file |
11.2 Example
?read.table
read.table(file, header = FALSE, sep = "", quote = "\"'",
dec = ".", numerals = c("allow.loss", "warn.loss", "no.loss"),
row.names, col.names, as.is = !stringsAsFactors,
na.strings = "NA", colClasses = NA, nrows = -1,
skip = 0, check.names = TRUE, fill = !blank.lines.skip,
strip.white = FALSE, blank.lines.skip = TRUE,
comment.char = "#",
allowEscapes = FALSE, flush = FALSE,
stringsAsFactors = default.stringsAsFactors(),
fileEncoding = "", encoding = "unknown", text, skipNul = FALSE)
read.csv(file, header = TRUE, sep = ",", quote = "\"",
dec = ".", fill = TRUE, comment.char = "", ...)
- Note:
- Data are read in using connection interfaces. Connections are commonly made to files or to other formats like
url
,gzfile
,bzfile
etc.
- The
foreign
library support to read data in several proprietary formats. - The
RStudio
IDE also supports to read data in several proprietary formats like Excel, SAS, SPSS and Stata.
- Data are read in using connection interfaces. Connections are commonly made to files or to other formats like