Learning R cheatsheet
Note: This post is over 10 years old. The information may be outdated.
Getting help:
help(x) or ?x # help on function `x`
example(x) # print an example of using `x`
??x # search help for instances of string x
apropos('x') # list all objects with `x` in the name
Types/objects:
mode(x) # type of an object (storage mode)
str(x) # display the structure of an object
ls() # list the objects in the current workspace
rm(x) # delete the object from curren workspace
File management:
getwd() # list working directory
setwd('dir') # set working directory
dir() # list directories
dir.create(...) # create a directory
Workspace:
save(...) # save objects to a file
save.image() # save entire image to a file
load('file') # load objects written by save
history() # display last few commands
savehistory('f') # save history to a file
loadhistory('f') # load history from a file
options() # list available options (globals)
options(x=3) # set an option
q() # quit session
Stream management:
source('f') # run commands from file `f`
sink('f', split=TRUE) # Tee output into a file
Package management:
.libPaths() # dir where are packages saved
installed.packages() # see details/versions/etc.
install.packages() # installation of packages
update.packages() # updating to latest
library() # list of installed packages
library(x) # load package
help(package='x') # get help on a package
Basic stats/math:
data() # list available datasets
runif(x) # generate x uniformly distributed numbers
rnorm(x) # generate x normally distributed numbers
summary(x) # print summary info for statistical objects
lm(x~y[, data=z]) # linear regression
integrate(f, i, j) # integrate `f` in range
Plotting basics:
dev.new() # create new plotting device and set active
def.off() # delete the last plotting device
png/pdf('x') # write graphics to a file
hist(x) # compute a histogram object (and plot by default)
plot(x, y) # plot `x` against `y`
plot(x~y) # plot `x` against `y`
plot(x~y, data=z) # plot `x` against `y` from dataframe
abline(...) # add a line to plot
curve(dnorm, -4, 4) # plot a function
Vectors:
x<-c(1, 2, 3) # constructor
x[1] # 1-based indexes
x[5]<-5 # expansion
x[c(1,2)] # get multiple indexes
1:5 # range (inclusive)
Factors:
# efficient storage of low cardinality
factor(c('x', 'y', 'z', 'x'))
Data frames:
data.frame(v1, v2) # populate a two-column data frame
names(x)<-c('a', 'b') # name the columns
x[2] # get a column
x['b'] # get a column
x$b # get a column
x[2:3] # get multiple columns
x[,2:3] # get multiple columns
with(x, { a }) # refer to a column, save typing
x[2:3,] # get multiple rows
Related Posts
Deploy Deep Learning model as a web service API
Trong bài này mình sẽ hướng dẫn deploy 1 model Deep learning, cụ thể là Keras dưới dạng một web service API. Sử dụng Flask framework python và Redis server như một Messeage Queue.
Sử dụng PyTorch với GPU miễn phí trên Google Colab
Google Colab (https://colab.research.google.com/) là một phiên bản Jupyter/iPython đến từ Google (think iPython + Google Drive), cung cấp cho chúng ta một môi trường notebook-based với backend Python 2/3 miễn phí. Google Colab rất hữu ích trong việc chia sẻ, giáo dục và teamwork trong các dự án về Machine Learning.
Propel - Machine learning for Javascript
Propel cung cấp cơ chế GPU-backed giống như thư viện Numpy trên Python, propel có thể cung cấp 1 kiến trúc rất mạnh cho các thuật toán Machine learning trên Javascript, như hỗ trợ tính toán rất mạnh và nhanh, như các tính toán trên ma trận, list, plot, ...
Duckling - phân tích văn bản sang dữ liệu có cấu trúc
Duckling là một thư viện của Haskell, phát triển bởi Facebook, rất hay để phân tích (parses) dữ liệu text sang dạng có cấu trúc (structured data). Công cụ này rất hữu ích trong các ứng dụng phân tích văn bản trong NLP và nhất là lĩnh vực chatbot.