- Created in 1976 as a programming language for statisticians
- Based on S language (is a dialect of S language)
- Interactive
- Packets-based
- Amazing for data visualization
- Open source, free to use
- Weak 3D visualization support
- In memory storage - issue when huge amount of data
- Five basic types -
character
,numeric
,integer
,complex
andlogical
vector
- base for complex data, can store items of one type- Numbers are as default
numeric
(float value), forinteger
we need useL
padding (eg.12L
) - Special
Inf
(infinity) andNaN
(not a number)
- For object we can use
names
,dimnames
,dimensions
,class
,length
and many prepared by user metadata - Attributes can be write / read by function
attributes()
variable <- value
where<-
mean assign#
we should use to start comment- Display variable: just write
variable
or directlyprint(variable)
c()
can be used to concatenate objects into vector (you can use alsovector()
constructor)- Sometimes we should use cast function
as.numeric
or anotheras.TYPE
, if cast fail as resultNA
- Vector with attribute
dimension
(vectornrow
,ncol
) - Can be created by
matrix(nrow = X, ncol = Y)
cbind(x, y)
orrbind(x, y)
can be used to create matrix with filled fields
- Can store elements of many types
- Constructor
list(elem1, elem2, ...)
- Can store tabularized data with named columns
data.frame(foo = 1:4, bar = c(T, T, F, F))
generate matrix withnrow(x) = 4
andncol(x) = 4
foo bar
1 1 TRUE
2 2 TRUE
3 3 FALSE
4 4 FALSE
- In R called
factor
type - Each value
level
can be represented by integer value with string - Can be
orderly
ornon orderly
(nominal)
NA
- Not Available valuesNaN
also is a missing value- Has own
class
attribute soNA
forinteger
can be different than forcharacter
is.na/1
oris.nan/1
checks - as returnTRUE | FALSE
- Missing values can be removed (filtered) by
complete.cases(data source)
- With
[logical query]
or[num]
we can filter vectors - With
[[field name]]
is possible to select element from lists, we can use variables $
can be used to fetch field by name, can't use here variables - only character name- For matrix we can use
[index_X, index_Y]
to select single value. When we decide to ignoreindex_X
orindex_Y
will receive whole rows / columns.
For $
and [[
we can use partial match but always we must receive at most one record.
if { ... }
for(var in source) { ... }
while(check) { ... }
repeat { ... }
-do-while
, we need usebreak
to stop it manuallynext
- skip iteration,continue
meaningreturn()
to exit value, this is a function!
function(parameters) { ... }
- we can ignore parameters which are not used in function's body (for example -function(a, b) { a }
-b
can be ignored in function's call)
traceback
- call stackdebug
- mark function to inspectionbrowser
- pause execution and switching to debug mode