CHAPTER4. SLANGUAGE
33
Iteration
repeat expr
while ( expr ) expr
for ( Name in expr ) expr
Flow
break
next
return ( expr )
( expr )
{ exprlist }
4.9.2 Arithmetic Operators
*
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
4.9.3 Relational Operators
!=
Not-equal-to
<
Less-than
<=
Less-than-or-equal-to
==
Equal
How to add pdf to powerpoint - SDK software API:C# Create PDF from PowerPoint Library to convert pptx, ppt to PDF in C#.net, ASP.NET MVC, WinForms, WPF
Online C# Tutorial for Creating PDF from Microsoft PowerPoint Presentation
www.rasteredge.com
How to add pdf to powerpoint - SDK software API:VB.NET Create PDF from PowerPoint Library to convert pptx, ppt to PDF in vb.net, ASP.NET MVC, WinForms, WPF
VB.NET Tutorial for Export PDF file from Microsoft Office PowerPoint
www.rasteredge.com
CHAPTER 4. S LANGUAGE
34
>
Greater-than
>=
Greater-than-or-equal-to
4.9.4 Logical Operators
!
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.
4.9.5 Subscripts
[ ]
Vector subscript
[[ ]] list subscript - can only identify a single element
$
Named component selection from a list
Subscript Forms
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
4.9.6 Sequence and Repetition
seq (from, to, by, length, along)
also
:
as in 1:10
rep(x, times, length)
SDK software API:C# PDF insert image Library: insert images into PDF in C#.net, ASP
C#.NET PDF SDK - Add Image to PDF Page in C#.NET. How to Insert & Add Image, Picture or Logo on PDF Page Using C#.NET. Add Image to PDF Page Using C#.NET.
www.rasteredge.com
SDK software API:VB.NET PDF insert image library: insert images into PDF in vb.net
VB.NET PDF - Add Image to PDF Page in VB.NET. Guide VB.NET Programmers How to Add Images in PDF Document Using XDoc.PDF SDK for VB.NET.
www.rasteredge.com
CHAPTER 4. S LANGUAGE
35
4.9.7 Arithmetic Operators and Functions
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)
4.9.8 Types
Can be used in as.<type> and is.<type> and <type>(length)
array
category
is, as only
character
complex
double
integer
list
logical
matrix
null
is, as only
numeric
SDK software API:VB.NET PDF Password Library: add, remove, edit PDF file password
VB: Add Password to PDF with Permission Settings Applied. This VB.NET example shows how to add PDF file password with access permission setting.
www.rasteredge.com
SDK software API:C# PDF Password Library: add, remove, edit PDF file password in C#
C# Sample Code: Add Password to PDF with Permission Settings Applied in C#.NET. This example shows how to add PDF file password with access permission setting.
www.rasteredge.com
CHAPTER 4. S LANGUAGE
36
4.9.9 In and Out of S
Data In
scan(file="", what=numeric(), n, sep,
multi.line = F, flush = F, append = F)
Example: data <- matrix(scan("data.file"),ncol=5,byrow=T)
Command File In
source(file, local = F)
Screen Output to File
sink(file)
sink( )
restores output to screen
Write and Read Objects
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’)
Make Things (Including Help) Available or Unavailable
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")
SDK software API:C# PDF Sticky Note Library: add, delete, update PDF note in C#.net
C#.NET PDF SDK - Add Sticky Note to PDF Page in C#.NET. Able to add notes to PDF using C# source code in Visual Studio .NET framework.
www.rasteredge.com
SDK software API:C# WinForms Viewer: Load, View, Convert, Annotate and Edit
allowed to load and view PowerPoint without Microsoft Office software installed, create PDF file, Tiff image and HTML file from PowerPoint, add annotations to
www.rasteredge.com
CHAPTER 4. S LANGUAGE
37
4.9.10 Reduction Operators
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)
4.9.11 Statistical Distributions
d<dist>(x,<parameters>)
density at x
p<dist>(x,<parameters>)
cumulative distn fn to x
q<dist>(p,<parameters>)
inverse cdf
r<dist>(n,<parameters>)
generates n random numbers from distn
<dist>
Distribution
Parameters
Defaults
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
4.9.12 Plotting
Starting and Stopping Plotting
<device-specification function>
graphics.off()
SDK software API:C# HTML5 Viewer: Load, View, Convert, Annotate and Edit PowerPoint
load and view PowerPoint without Microsoft Office software installed, convert PowerPoint to PDF file, Tiff image and HTML file, as well as add annotations in
www.rasteredge.com
SDK software API:RasterEdge XDoc.PowerPoint for .NET - SDK for PowerPoint Document
Convert. Convert PowerPoint to PDF. Extract, copy and paste PowerPoint Pages. Annotation & Thumbnail. Add and burn annotation to PowerPoint.
www.rasteredge.com
CHAPTER 4. S LANGUAGE
38
Device-Specification Functions
postscript(file, command, horizontal=F, width,
height, rasters, pointsize=14, font=1,
preamble=ps.preamble, fonts=ps.fonts)
Some Plot Parameters
log=’<x|y|xy>’
Logarithmic axes
main=’title’
new=<logical>
T forces addition to current plot
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)
One-Dimension Plots
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)
Two-Dimension Plots
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)
CHAPTER 4. S LANGUAGE
39
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)
Three-Dimension Plots
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)
Multiple Plots Per Page (Example)
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")
Chapter 5
Objects, Getting Help, Functions,
Subsetting, Attributes, and Libraries
5.1 Objects—General
AH 2.1,KOp.70
·
Everything in S is an object
·
Work on objects by applying functions to them
·
Usually an object is ultimately committed to a disk file with the same name
as the S object
a
5.2 Functions
KO4.2,AH2.3
5.2.1 Getting Help
AH 2.2,KO3.1.2
·
To find out how to use a function
a
In Windows, diskfile names do not correspond to object namesif the objectname is longerthan 8 characters.
40
CHAPTER 5. OBJECTS, GETTING HELP, FUNCTIONS, SUBSETTING, ATTRIBUTES, AND LIBRARIES
41
·
At command line (or submit run using
F10
if using
Script
window) type
?functionname
if you know its name
·
May want to look at examples first then work backwards to details
·
Specifications and data are passed to functions as arguments
·
If you know what a function does and just need to know the names and order
of its arguments type
args(functionname)
This also shows the default values of the arguments that are used when you
do not provide a value for the function.
Note:Whenthedefaultvalueforanargumentisavectorlike
c(value1,value2,value3)
, and the argument really takes a scalar value,
thedefaultvalue for the argument is
value1
and the other values are the
only otherpossible values for that argument.
·
Sometimes you need to find out exactly what a function does. You can often
print its full definition by running the command
functionname
, which runs
print(functionname)
.
·
For Windows S-P
LUS
there are good ways to find which function to use by
using the
Language Reference
submenu on the
Help
menu:
– tellyouwhichfunctionscontainawordorphraseyouspecifyanywhere
in its help file, and let you click on one of those functions to see its help
file if you click on
Search
– putofalistofkeywordsaroundwhichfunctionsareorganizedandletyou
click on a keyword to list all the functions related to that area if you click
on
Contents
;then you can go to help files for individual functions
AH 2.2
·
There is also a nice keyword-organized function guide at
http://insightful.
com/resources/fguide.html
although this web site does not contain individ-
ual help files
CHAPTER 5. OBJECTS, GETTING HELP, FUNCTIONS, SUBSETTING, ATTRIBUTES, AND LIBRARIES
42
5.2.2 Using Functions
·
An S command line can look like
functionname(argument1, argument2, argument3)
which will run function
functionname
on the values given by thearguments
argument1, argument2, argument2
and will print the resultreturned by the
function
·
Arguments are frequently calledparameters, especially when you are look-
ing inside the body of a function definition
·
Some functions which only do things such as make a plot in a graphics
window or to a graphics device do not have any results printed
·
Often functions are invoked using a format such as
functionname(major.data.object, otherarguments)
where
otherarguments
are variables or constants whose values tell the func-
tion how to operate on the main data given by
major.data.object
or they
tell the function exactly what the function should compute
·
We often think of such other arguments asoptions
·
For many functions, we pass the first argument byposition, which means
that the function will know what to do with that object by virtue of it being the
first argument
·
This first argument is often a variable to analyze
·
Other arguments may also be specified by position, but functions have to
give their own internal names for arguments and we can match arguments
to values we defined by specifying argument names in the form
argumentname=our.value
Documents you may be interested
Documents you may be interested