R Programming: © 2016 SMART Training Resources Pvt. LTD
R Programming: © 2016 SMART Training Resources Pvt. LTD
R Programming: © 2016 SMART Training Resources Pvt. LTD
1. The Basics
2. R Data Structures
3. Data Input/Output
4. In-Built Functions
5. Data Visualization
What R does and does not
• data handling and storage: • is not a database, but
numeric, textual connects to DBMSs
1.0
> 2+3; 5*9; 6-6
[1] 5
[1] 45
0.5
sin(seq(0, 2 * pi, length = 100))
[1] 0
0.0
> log2(32)
[1] 5
-0.5
> sqrt(2)
[1] 1.414214
-1.0
Index
[1] 0 1 2 3 4 5
> plot(sin(seq(0, 2*pi, length=100)))
Variables
> i = 81
> sqrt(i) numeric
[1] 9
> 1>2
[1] FALSE logical
Object orientation
primitive (or: atomic) data types in R are:
Vector
Matrix
Array
Factor
Data Frame
List
Vectors
• vector: an ordered collection of data of the same type
> a = c(1,2,3)
> a*2
[1] 2 4 6
Example:
>a
localisation tumorsize progress
XX348 proximal 6.3 FALSE
XX234 distal 8.0 TRUE
XX987 proximal 10.0 FALSE
Factors
• A character string can contain arbitrary text. Sometimes it is useful
to use a limited vocabulary, with a small number of allowed
words. A factor is a variable that can only take such a limited
number of values, which are called levels.
• Example
• a family of two girls (1) and four boys(0),
>kids = factor(c(1,0,1,0,0,0),levels=c(0,1),
labels=c("boy","girl"))
> Kids
[1] girl boy girl boy boy boy
Levels: boy girl
> class(kids)
[1] "factor"
Data Input/Output
Directory management
• dir() list files in directory
• setwd(path) set working directory
• getwd() get working directory
• ?files File and Directory Manipulation