The R Language
A Hands-on Introduction
Venkatesh-Prasad Ranganath http://about.me/rvprasad
The R Language A Hands-on Introduction Venkatesh-Prasad Ranganath - - PowerPoint PPT Presentation
The R Language A Hands-on Introduction Venkatesh-Prasad Ranganath http://about.me/rvprasad What is R? A dynamical typed programming language http://cran.r-project.org/ Open source and free Provides common programming language
Venkatesh-Prasad Ranganath http://about.me/rvprasad
b c
[ <- is the assignment operator ]
[ m
: n is equivalent to seq( m , n, 1) ]
[ no nesting / always flattened ]
[ 1-based indexing ]
[ Negative subscripts imply exclusion ]
es( x) <-
[ Makes equivalent to x[ 1] ]
[ Vectorized operations ]
U E, TR U E)
hi ch( x > 5) = c( 2, 3)
aN , x) = c( 5, N aN , N aN )
U E
[ How about al l ( x > 5) ? ]
( c( 1, 2, 3, N A) , na. r m = TR U E) = 6
[ Why is na. r mrequired? ]
at r i x( nr ow =2, ncol =3) [ empty matrix ]
at r i x( c( 1, 2, 3, 4, 5, 6) , nr ow =2) =
at r i x( c( 1, 2, 3, 4, 5, 6) , nr ow =2, byr ow =T) =
= 2
=
[ How about y[ 1, ] ? ]
1 3 5 2 4 6 1 2 3 4 5 6 2 3 5 6
nam es( ) and col nam es( )
( y) = 2
[ number of rows ]
[ number of columns ]
) = c( 6, 15)
[ apply sumto each row ]
) = c( 5, 7, 9)
[ apply sumto each column ]
[ transpose a matrix ]
1 4 2 5 3 6
1 2 3 4 5 6 7 8 9 1 2 3 7 4 5 6 8
m <- m at r i x( nr ow =4, ncol =4) m <- i f el se( r ow ( m ) == col ( m ) , 1, 0. 3)
[ f1 and f2 are tags ]
[ How about k[ 2] ? ]
[ Is it same as l [ 1] or l [ [ 1] ] ? ]
es( k) <-
) = l i st ( 3, 19)
) = c( 3, 19)
U LL = ???
different types.
e j i l l
es j i l l
[ How about x[ [ 1] ] ? ]
= ???
= ???
nam es( ) and col nam es( )
= dat a. f r am e j i l l ) )
) = ???
e( 1: 3, 5: 7)
ean) = ???
ean) = ???
ean) = ???
<- f act or ( c( 1: 3, 2, 4: 5) )
i t h( m t car s, spl i t ( m pg, cyl ) ) = ???
i t h( m t car s, t appl y( m pg, cyl , m ean) ) = ???
t car s, m t car s$cyl , f unct i on( m ) { m edi an( m $m pg) } = ???
t car s, l i st ( m t car s$cyl ) , m edi an) = ???
i t h( m t car s, boxpl ot ( m pg) )
t car s$m pg)
i t h( m t car s, pl ot ( hp, m pg) )
eat hs)
t car s, l i st ( m t car s$cyl ) , m edi an) )
You can get the list of datasets via l s
ean
edi an
Let’s get out hands dirty!!