
298 APPENDIX B. R QUICK START
us e r system e l a ps e d
0. 0 0 8 0 .00 0 0 . 006
> system . time ({s <− 0 ;
for ( i i n 1:10 0 0 000 ) s <− s + x [ i ] })
us e r system e l a ps e d
2. 7 7 6 0 .00 4 2 . 859
B.4 Second Sample Programming Session
A matrix is a special case of a vector, with added class attributes, the
numbers of rows and columns.
# rowbind () fu n c t i o n combines rows o f m a tri c e s ;
# there ’ s a cbind () f o r columns too
> m1 <− rbind ( 1 : 2 , c ( 5 , 8 ) )
> m1
[ , 1 ] [ , 2 ]
[ 1 , ] 1 2
[ 2 , ] 5 8
> rbind (m1, c (6 , −1))
[ , 1 ] [ , 2 ]
[ 1 , ] 1 2
[ 2 , ] 5 8
[ 3 , ] 6 −1
# form matri x from 1 ,2 ,3 ,4 ,5 , 6 , in 2 rows ;
# R u