2 R basics

2.1 Basic operations

> 2+2
## [1] 4
> 
> 7*17
## [1] 119
> 
> sqrt(9)
## [1] 3
> 
> 3^3
## [1] 27
> 
> log(7)
## [1] 1.94591
> 
> log10(7)
## [1] 0.845098

2.2 Precision

> sin(pi/2)
## [1] 1
> 
> pi
## [1] 3.141593
> 
> options(digits=22)
> 
> pi
## [1] 3.141592653589793115998
> 
> options(digits=4)

2.3 Infinity or not defined, and missings

> 1/0  
## [1] Inf
> 
> 2*Inf
## [1] Inf
> 
> -1/0
## [1] -Inf
> 
> 0/0
## [1] NaN
> 
> c(1,2,3,NA,5)
## [1]  1  2  3 NA  5
> 
> mean(c(1,2,3,NA,5))
## [1] NA
> 
> mean(c(1,2,3,5))
## [1] 2.75

2.4 Important commands

> ls()                            #...display list of variables in memory
> 
> ls.str()                        #...display the structure os the list of variables in memory
> 
> rm(a)                           #...remove an object
> 
> rm(list=ls())                   #...remove ALL objects
> 

2.5 Internal help function

> help(mean)    # shorthand for help(mean)
> example(mean)    # examples
> help.search("mean")   # full information
> help.start()   # manuals