The very short introduction to R

Some history

  • Developed as reduced version of S (later S-plus, spotfire)
  • Released as open source in 1995
  • At that time the only statistical package available for Linux

Installation

  • www.r-project.org to download R
  • www.rstudio.com to download Rstudio
  • Think of it as SAS versus SAS EG

R as an overgrown calculator

## [1] 4
## [1] 0.1353353
##  [1] -1.31610441 -0.68287241 -0.13930987 -1.37804907 -0.14774243
##  [6] -0.86050033 -1.04545518 -0.40769396 -0.34812848  1.57435674
## [11]  1.41489930  0.09422239 -0.52949356  0.96144952 -0.48719970

Assignments

## [1] 2
## [1] 4

More on vectors

## [1] TRUE
## [1] TRUE
## [1] FALSE
## [1] TRUE
## [1]  TRUE  TRUE FALSE  TRUE
## [1] FALSE FALSE FALSE FALSE  TRUE FALSE
## [1] 4 5 6 7 8 9
## [1] 4 5 6 7 8 9
## [1]  4  6  8 10
## [1]  7  9 13  7  9 13  7  9 13
## [1]  7  9  9 13 13 13
##  [1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

Data frames - now SAS users know what is going on

## [1] "intake_pre"  "intake_post"
## [1] 11  2
##  [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770
## NULL
## [1] "intake_pre"  "intake_post" "subjid"
## [1] 11  3
##    intake_pre intake_post subjid
## 1        5260        3910      1
## 2        5470        4220      2
## 3        5640        3885      3
## 4        6180        5160      4
## 5        6390        5645      5
## 6        6515        4680      6
## 7        6805        5265      7
## 8        7515        5975      8
## 9        7515        6790      9
## 10       8230        6900     10
## 11       8770        7335     11
## [1] 5260
## [1] 5260
##   intake_pre intake_post subjid
## 1       5260        3910      1
## 3       5640        3885      3
## 7       6805        5265      7
##    intake_pre intake_post subjid
## 2        5470        4220      2
## 4        6180        5160      4
## 5        6390        5645      5
## 6        6515        4680      6
## 8        7515        5975      8
## 9        7515        6790      9
## 10       8230        6900     10
## 11       8770        7335     11
##   subjid intake_pre intake_post age_group
## 1      1       5260        3910       old
## 2      2       5470        4220     young
## 3      3       5640        3885       old
## 4      4       6180        5160     young
## 5      5       6390        5645       old
## 6      6       6515        4680     young
## 7      7       6805        5265       old
## 8      8       7515        5975     young
##    intake_pre intake_post subjid low_pre_fl
## 1        5260        3910      1          1
## 2        5470        4220      2          1
## 3        5640        3885      3          1
## 4        6180        5160      4          0
## 5        6390        5645      5          0
## 6        6515        4680      6          0
## 7        6805        5265      7          0
## 8        7515        5975      8          0
## 9        7515        6790      9          0
## 10       8230        6900     10          0
## 11       8770        7335     11          0

Descriptive statistics

##    intake_pre    intake_post       subjid       low_pre_fl    
##  Min.   :5260   Min.   :3885   Min.   : 1.0   Min.   :0.0000  
##  1st Qu.:5910   1st Qu.:4450   1st Qu.: 3.5   1st Qu.:0.0000  
##  Median :6515   Median :5265   Median : 6.0   Median :0.0000  
##  Mean   :6754   Mean   :5433   Mean   : 6.0   Mean   :0.2727  
##  3rd Qu.:7515   3rd Qu.:6382   3rd Qu.: 8.5   3rd Qu.:0.5000  
##  Max.   :8770   Max.   :7335   Max.   :11.0   Max.   :1.0000