R notes[1]

发布于:2025-09-02 ⋅ 阅读:(17) ⋅ 点赞:(0)

fundational knowldege

  1. the R command provides an entry to start the R program. the Q quit R terminal.
  2. in R termina, help(func) show how to use the func function .
  3. R code is case sensitive.
  4. source("commands.R") run the code stored in file named commands.R.
  5. sink("doc.lis") will divert output from standard ouput device to the doc.lis file stored in your disk.
  6. 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).
  7. 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 as c(1.1,2.3,53.2)->x.by the way, there are other way to achieve assignment assign("x", c(1.1,2.3,53.2)).
  8. 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

references

  1. https://cran.r-project.org/doc/manuals/

网站公告

今日签到

点亮在社区的每一天
去签到