Documente Academic
Documente Profesional
Documente Cultură
Paul Teetor
Chicago R User's Group
November 2011
Do It the R Way
Or: B+x,Bx,B/x,B%%x
C
1
2
3
B
10
20
30
40
50
60
70
80
90
C
1
2
3
1
2
3
1
2
3
A
11
22
33
41
52
63
71
82
93
apply(M,1,fun)
apply(M,2,fun)
sapply(lst,fun)
mapply(fun,lst1,lst2,...)
Apply a function
tapply(x,factor,fun)
vapply(lst,fun,...)
- A faster version of
lapply; see the help page for details
>x
[1]7820982137
>odd<function(n)(n%%2==1)
>Filter(odd,x)
[1]2137
Reduce(f,x)
vector, x, by
results of f.
Suppose x = x1,x2,x3,x4,x5,...
Reduce(f,x)
is a function of two arguments, and x is
a list or vector
f(a,b)
Iterative summation:
s<x[1]+x[2]
for(iin3:length(s))s<s+x[i]
Cumulative product:
f<function(a,b)a*b
prods<Reduce(f,x,accumulate=TRUE)
Fast(er) R Code
Slides on-line at
http://quanttrader.info/public
paulteetor@yahoo.com
@pteetor