fundational knowldege
- the
R
command provides an entry to start the R program. theQ
quit R terminal. - in R termina,
help(func)
show how to use the func function . - R code is case sensitive.
source("commands.R")
run the code stored in file namedcommands.R
.sink("doc.lis")
will divert output from standard ouput device to thedoc.lis
file stored in your disk.- anything that your code create and operate in R are objects,so objects() can help you to inspect the information of those objects.of course you have the right to delete them through
rm(object name)
,for example ,rm(a, b, c)
. - the objects of R have not
scalar
type,that is to say,variable belongs to Vector or more complex data structure.if you assign values to a variable ,you can use<-
operator,for example,x <- c(1.1,2.3,53.2)
. If you prefer to place the variable on the right side,the->
operator is the best choice,such asc(1.1,2.3,53.2)->x
.by the way, there are other way to achieve assignmentassign("x", c(1.1,2.3,53.2))
. - some mathematic manipulationes in vector will generate a new vector,for example:
> x<-c(1,2,3,4,5.5)
> x+1
[1] 2.0 3.0 4.0 5.0 6.5
> x-1
[1] 0.0 1.0 2.0 3.0 4.5
> x/5
[1] 0.2 0.4 0.6 0.8 1.1
but few operationes impacted on vector will generate a vector just only involves one element as follows.
> mean(x)
[1] 3.1
> x-mean(x)
[1] -2.1 -1.1 -0.1 0.9 2.4
> 5**2
[1] 25
> sqrt(sum((x-mean(x))**2))
[1] 3.49285