Input and output Flashcards Preview

R > Input and output > Flashcards

Flashcards in Input and output Deck (15)
Loading flashcards...
1

load()

load the datasets written with save

2

data(x)

loads specified data sets

3

library(x)

load add-on packages

4

read.table(file)

reads a file in table format and creates a data
frame from it; the default separator sep="" is any whitespace; use header=TRUE to read the first line as a header of column names; use as.is=TRUE to prevent character vectors from being converted to fac- tors; use comment.char="" to prevent "#" from being interpreted as a comment; use skip=n to skip n lines before reading data; see the help for options on row naming, NA treatment, and others

5

read.csv("filename",header=TRUE)

id. but with defaults set for reading comma-delimited files

6

read.delim("filename",header=TRUE)

id. but with defaults set for reading tab-delimited files

7

read.fwf(file,widths,header=FALSE,sep=""

read a table of f ixed width f ormatted data into a ’data.frame’; widths
is an integer vector, giving the widths of the fixed-width fields

8

save(file,...)

saves the specified objects (...) in the XDR platform-
independent binary format

9

save.image(file)

saves all objects

10

cat(..., file="", sep=" ")

prints the arguments after coercing to
character; sep is the character separator between arguments

11

print(a, ...)

prints its arguments; generic, meaning it can have differ-
ent methods for different objects

12

format(x,...)

format an R object for pretty printing

13

write.table(x,file="",row.names=TRUE,col.names=TRUE,
sep=" ")

prints x after converting to a data frame; 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; use col.names=NA to add a blank column header to get the column headers aligned correctly for spreadsheet input

14

sink(file)

output to file, until sink()
Most of the I/O functions have a file argument. This can often be a charac- ter string naming a file or a connection. file="" means the standard input or output. Connections can include files, pipes, zipped files, and R variables. On windows, the file connection can also be used with description = "clipboard". To read a table copied from Excel, use
x ,col.names=NA)
For database interaction, see packages RODBC, DBI, RMySQL, RPgSQL, and ROracle. See packages XML, hdf5, netCDF for reading other file formats.

15