R is an integrated suite of software facilities for data manipulation, calculation and graphical display
Action | Operator | Example |
---|---|---|
Create / update a variable | <- | a <- 10 |
Comment | # | # This is my comment |
Help | ? | ?mean |
Identifier | ` | `1`<-2 |
Get a component e.g a data.frame column | $ | iris$Sepal.Length |
Reference positions within an object | [ ] | iris[ 1 , 1] |
Task | How |
---|---|
Read CSV | irisDT <- fread(“iris.csvâ€) |
Return everything | irisDT irisDT[ ] |
Select columns | irisDT[ , .(Sepal.Length, Sepal.Width) ] |
Restrict rows | irisDT[ Sepal.Length >=5 , ] |
Aggregate | irisDT[ , mean(Sepal.Length)] |
Aggregate by group | irisDT[ , mean(Sepal.Length) , Species ] |
Count | irisDT[ , .N ] |
Hadley Wickham, insanely prolific developer of R packages has produced a great ecosystem:
Term | Explanation | Example(s) |
---|---|---|
plot | A plot using the grammar of graphics | ggplot() |
aesthetics | attributes of the chart | colour, x, y |
mapping | relating a column in your data to an aesthetic | |
statistical transformation | a translation of the raw data into a refined summary | stat_density() |
geometry | the display of aesthetics | geom_line() , geom_bar() |
scale | the range of values | axes, legends |
coordinate system | how geometries get laid out | coord_flip() |
facet | a means of subsetting the chart | facet_grid() |
theme | display properties | theme_minimal() |
A single point of contact for myriad statistical & machine learning algorithms
Interact with AzureML in R
Write markdown, interweave code
Make your own CRAN
library(devtools)
pkg<-"newPackage"
create(pkg)
library(devtools) # Open the project!
add_test_infrastructure() # Add unit test framework
add_travis() # Add CI framework
use_vignette() # Add folder for macro-level help files
use_package_doc() # Add file for providing info about your package
use_readme_rmd() # Make a README!
myfunc<-function(a=1,b=2,c="blah"){
stopifnot(is.numeric(a), is.numeric(b), is.character(c))
d<-ifelse(a<0,a*b,a/b)
e<-paste0(c,d)
return(e)
}
library(testthat)
# Add a high-level name for group of tests, typically the function name
context("myfunc")
# Simplest test
test_that("Defaults return expected result",{
result<-myfunc()
check<-"blah0.5"
expect_equal(result,check)
})