1. Reading Data
read.table (If large dataset, provide colClasses and nrows)
read.csv
readLines
source
dget
load
unserialize
2. File Connections
str(file)
- r
- w
- a
- rb, wb, ab
con <- file("foo.txt", "r")
data <- read.csv(con)
close(con)
data <- read.csv("foo.txt")
con <- gzfile("words,gz")
x <- readLines(con, 10)
3. Subsetting
- [ extract same class
x[1]
x[x > "a"]
x[c(1,3)]
x[1, , drop = FALSE]
- [[ extract list or data frame
x[[1]]
x[["bar"]]
x[[2]][[1]]
- $ extract by name
x$bar
- partial matching
x <- list(aardvark = 1:5)
x[["a", exact = FALSE]]
- removing NA values
x<- c(1,2,NA,4,NA,5)
bad<- is.na(x)
x[!bad]