This preview shows page 1. Sign up to view the full content.
Unformatted text preview: vector; can also assign, as substr(x, start, stop) <- value
strsplit(x,split) split x according to the substring split
grep(pattern,x) searches for matches to pattern within x; see ?regex
gsub(pattern,replacement,x) replacement of matches determined
by regular expression matching sub() is the same but only replaces
the ﬁrst occurrence.
tolower(x) convert to lowercase
toupper(x) convert to uppercase
match(x,table) a vector of the positions of ﬁrst matches for the elements
of x among table
x %in% table id. but returns a logical vector
pmatch(x,table) partial matches for the elements of x among table nchar(x) number of characters Dates and Times
The class Date has dates without times. POSIXct has dates and times, including time zones. Comparisons (e.g. >), seq(), and difftime() are useful.
Date also allows + and −. ?DateTimeClasses gives more information. See
also package chron.
as.Date(s) and as.POSIXct(s) convert to the respective class;
format(dt) converts to a string representation. The default string
format is “2001-02-21”. These accept a second argument to specify a
format for conversion. Some common formats are:
%a, %A Abbreviated and full weekday name.
%b, %B Abbreviated and full month name.
%d Day of the month (01–31).
%H Hours (00–23).
%I Hours (01–12).
%j Day of year (001–366).
%m Month (01–12).
%M Minute (00–59).
%p AM/PM indicator.
%S Second as decimal number (00–61).
%U Week (00–53); the ﬁrst Sunday as day 1 of week 1.
%w Weekday (0–6, Sunday is 0).
%W Week (00–53); the ﬁrst Monday as day 1 of week 1.
%y Year without century (00–99). Don’t use.
%Y Year with century.
%z (output only.) Offset from Greenwich; -0800 is 8 hours west of.
%Z (output only.) Time zone as a character string (empty if not available).
Where leading zeros are shown they will be used on output but are optional
on input. See ?strftime. Plotting
plot(x) plot of the values of x (on the y-axis) ordered on the x-axis
plot(x, y) bivariate plot of x (on the x-axis) and y (on the y-axis)
hist(x) histogram of the frequencies of x
barplot(x) histogram of the values of x; use horiz=FALSE for horizontal
dotchart(x) if x is a data frame, plots a Cleveland dot plot (stacked plots
line-by-line and column-by-column)
pie(x) circular pie-chart
boxplot(x) “box-and-whiskers” plot
sunflowerplot(x, y) id. than plot() but the points with similar coordinates are drawn as ﬂowers which petal number represents the number of points
stripplot(x) plot of the values of x on a line (an alternative to
boxplot() for small sample sizes)
coplot(x˜y | z) bivariate plot of x and y for each value or interval of
values of z
interaction.plot (f1, f2, y) if f1 and f2 are factors, plots the
means of y (on the y-axis) with respect to the values of f1 (on the
x-axis) and of f2 (different curves); the option fun allows to choose
the summary statistic of y (by default fun=mean) matplot(x,y) bivariate plot of the ﬁrst column of x vs. the ﬁrst one of y,
the second one...
View Full Document
- Fall '14