Input / Output
- source("my.R")
- data(f)
- library(s)
- read.table(f)
- sep="" is any whitespace by default
- header=TRUE to read the first line as a header of column names
- as.is=TRUE to prevent character vectors from being converted to factors
- comment.char="" to prevent "#" from being interpreted as a comment
- skip=n to skip n lines before reading data
- see the help for options on row naming, NA treatment, and others
- read.csv(f,header=TRUE)
- read.delim(f,header=TRUE)
- read.fwf(f,widths,header=FALSE,sep="",as.is=FALSE)
- widths is an integer vector, giving the widths of the fixed-width fields
- save(f,...)
- save.image(f)
- load(f)
- cat(..., file=f, sep="")
- print(a, ...)
- format(x, ...)
- write.table(x, file=f, row.names=TRUE, col.names=TRUE, sep="")
- if quote is TRUE, character or factor columns are surrounded by quotes (")
- sep is the field separator, eol is the end-of-line separator
- na is the string for missing values
- col.names=NA to add a blank column header to get the column headers aligned correctly for spreadsheet input
- sink(f)
- Most of the I/O functions have a file argument and means the standard input or output. Connections can include files, pipes, zipped files, clipboard and R variables
- df <- read.delim("clipboard")
- write.table(df,"clipboard",sep="\t",col.names=NA)
- For database interaction, see packages RODBC, DBI, RMySQL, RPgSQL, ROracle, for other file formats see XML, hdf5, netCDF
Data creation
- с(...)
- seq(from, to, by = )
- seq(from, to, len = )
- rep(x, times)
- list(...)
- data.frame(...)
- array(data, dims)
- matrix(data, nrow = , ncol = , byrow = )
- factor(x, levels = )
- gl(n, k, length = n*k, labels = 1:n)
- rbind(...)
- cbind(...)