
Educators: Earn a free Gold upgrade by joining the PBwiki Back To School Challenge.

Questions? Get live answers at PBwiki's weekly office hours (1 PM Eastern, Weds September 3)
expr <- expr
expr = expr
expr -> expr
if ( expr ) expr
if ( expr ) expr else expr
repeat expr
while ( expr ) expr
for ( Name in expr ) expr
Flow
break
next
return ( expr )
( expr )
{ exprlist }
* Multiply
+ Add
- Subtract
/ Divide
^ Exponentiation
%% Remainder or modulo operator
%*% Matrix multiplication operator
%/% Integer divide
%c% crossproduct m1 %c% m2 is t(m1) %*% m2
%o% Outer Product
!= Not-equal-to
< L ess-than
<= Less-than-or-equal-to
== Equal
> Greater-than
>= G reater-than-or-equal-to
'!' Not
| Or (Use with arrays or matrices)
|| Shortcut Or (Don’t use with arrays or matrices)
& And (Use with arrays or matrices)
&& Shortcut And (Don’t use with arrays or matrices)
Above “shortcut” means that if the condition is not satisfied, the remaining parts of the expression are not even
evaluated. This is very useful if these parts don’t even make sense then, or are slow to execute.
[ ] Vector subscript
[[ ]] list subscript - can only identify a single element
$ Named component selection from a list
logical extracts or selects T component
positive numbers extracts or selects specified indices
negative numbers deletes specified indices
NA or out of range extends dimensions gives value NA
seq (from, to, by, length, along)
also : as in 1:10
rep(x, times, length)
abs(x)
acos(x)
acosh(x)
asin(x)
asinh(x)
atan(x)
atan(x, y)
atanh(x)
ceiling(x)
cos(x)
cosh(x)
exp(x)
floor(x)
gamma(x)
lgamma(x)
log(x, base=exp(1))
log10(x)
max(...) elementwise
min(...) elementwise
pmax(...) parallel
pmin(...) parallel
sin(x)
sinh(x)
sqrt(x)
tan(x)
tanh(x)
trunc(x)
Can be used in as.
array
category is, as only
character
complex
double
integer
list
logical
matrix
null is, as only
numeric
scan(file="", what=numeric(), n, sep, multi.line = F, flush = F, append = F)
Example: data <- matrix(scan("data.file"),ncol=5,byrow=T)
source(file, local = F)
sink(file)
sink( ) restores output to screen
dput(x, file) writes out object in S notation
dget(file)
write(t(matrix),file,ncol=ncol(matrix),append=FALSE)
data.dump(objnames, file=’filename’) objnames may be ’obj name’
or c(’name1’,’name2’,...)
data.restore(’filename’)
assign("name", value, frame, where)
attach(file, pos=2)
detach(2)
library( )
library(help=section)
library(section, first=TRUE) make library’s functions take precedence
help(name="help", offline=F)
args(name="help")
all(...)
any(...)
length(x)
max(...)
mean(x, trim=0)
median(x)
min(...)
mode(x)
prod(...)
quantile(x, probs=c(0,.25,.5,.75,1))
sum(...)
var(x,y)
cor(x,y,trim=0)
d
p
q
r
beta beta shape1, shape2 -, -
cauchy Cauchy loc, scale 0, 1
chisq chi-square df -
exp exponential - -
f F df1, df2 -, -
gamma Gamma shape -
lnorm log-normal mean, sd (of log) 0, 1
logis logistic loc, scale 0, 1
norm normal mean, sd 0, 1
stab stable index, skew -, 0
t Student’s t df -
unif uniform min, max 0, 1
postscript(file, command, horizontal=F, width, height, rasters, pointsize=14, font=1, preamble=ps.preamble, fonts=ps.fonts)
x11()
jpeg()
png()
quartz()
graphics.off()
dev.off()
log=’<x|y|xy>’ Logarithmic axes
main=’title’
new=
sub=’bottom title’
type=’<l|p|b|n>’ Line, points, both, none
lty=n Line type
pch=’.’ Plot character
xlab=’x-axis label’
ylab=’y-axis label’
xlim=c(xlo.value,xhi.value)
ylim=c(ylo.value,yhi.value)
barplot(height) #simple form
barplot(height, width, names, space=.2, inside=TRUE,
beside=FALSE, horiz=FALSE, legend, angle,
density, col, blocks=TRUE)
boxplot(..., range, width, varwidth=FALSE,
notch=FALSE, names, plot=TRUE)
hist(x, nclass, breaks, plot=TRUE, angle,
density, col, inside)
lines(x, y, type="l")
points(x, y, type="p"))
matplot(x, y, type="p", lty=1:5, pch=, col=1:4)
matpoints(x, y, type="p", lty=1:5, pch=, col=1:4)
matlines(x, y, type="l", lty=1:5, pch=, col=1:4)
plot(x, y, type="p", log="")
abline(coef)
abline(a, b)
abline(reg)
abline(h=)
abline(v=)
qqplot(x, y, plot=TRUE)
qqnorm(x, datax=FALSE, plot=TRUE)
contour(x, y, z, v, nint=5, add=FALSE, labex)
interp(x, y, z, xo, yo, ncp=0, extrap=FALSE)
persp(z, eye=c(-6,-8,5), ar=1)
par(mfrow=(nrow, ncol), oma=c(0, 0, 4, 0))
mtext(side=3, line=0, cex=2, outer=T,
"This is an Overall Title For the Page")
Page Information
|
Wiki Information |
Recent PBwiki Blog Posts |